如何从jsp视图将子类对象返回给控制器。该页面接收带有子类元素的正确动物列表。我能够显示子类元素,但是当我试图将它发送回控制器时,我得到了一个绑定错误。这是我的问题的模拟代码。
public class Group
{
public List<Animal> animals;
//getters and setters
}
abstract class Animal
{
String name;
//getters and setters
}
class Lion extends animal
{
String legs;
//getters and setters
}我的观点是:
<form:hidden path="groups[${groupssList.index}].animals[${animalsList.index}].name"/>例外:
Could not instantiate property type [Animal] to auto-grow nested property path: java.lang.InstantiationException发布于 2013-10-21 23:49:27
我认为Spring值会导致一个null引用,而Spring会尝试用一个默认对象来填充它。要禁用此默认行为,请添加到(每个) @Controller类中。
@InitBinder
public void initBinder(WebDataBinder binder){
binder.setAutoGrowNestedPaths(false);
}你最终会得到一个不同的异常,但它会更清晰。
https://stackoverflow.com/questions/19499020
复制相似问题