我有以下类的一个实例,我想在其中进行编辑,然后将其保存回后端。
public class NestedClass {
List<InnerClass> inners = new LinkedList<InnerClass>();
//getter and setter
public class InnerClass {
private String innerField;
//getter and setter
}
}
编辑:编辑示例代码以满足@Slava Semushin 的建议。
当我实例化类并将其传递给模型时,我可以使用以下 jsp 片段读取值:
<form:input path="inners[0].innerField" /><br/>
<form:input path="inners[1].innerField" /><br/>
但是当我把它传回去时,我得到以下异常:
Invalid property 'inners[0]' of bean class [com.sodacrm.webapp.forms.NestedClass]: Illegal attempt to get property 'inners' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'inners' of bean class [com.sodacrm.webapp.forms.NestedClass]: Could not instantiate property type [com.sodacrm.webapp.forms.NestedClass$InnerClass] to auto-grow nested property path: java.lang.InstantiationException: com.sodacrm.webapp.forms.NestedClass$InnerClass
org.springframework.beans.InvalidPropertyException: Invalid property 'inners[0]' of bean class [com.sodacrm.webapp.forms.NestedClass]: Illegal attempt to get property 'inners' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'inners' of bean class [com.sodacrm.webapp.forms.NestedClass]: Could not instantiate property type [com.sodacrm.webapp.forms.NestedClass$InnerClass] to auto-grow nested property path: java.lang.InstantiationException: com.sodacrm.webapp.forms.NestedClass$InnerClass
我正在使用的真正类是 3 级深,我不想将内部类放在单独的文件中,因为它们强烈属于它们的外部类......