我试图在春季MVC中列出列表是否可能?我们需要编写任何自定义绑定方法吗?请帮我。
JSTL代码:
<input id="labelDTOS0.labelItemDTOS0.newValue"
name="labelDTOS[0].labelItemDTOS[0].newValue" type="text" value=""/>
DTO的:
public class LabelDTO {
public long id;
public String name;
public List<LabelItemDTO> labelItemDTOS;
}
public class LabelItemDTO {
public String value;
public String placeHolder;
public String newValue;
}
例外:
Invalid property 'labelDTOS[0].labelItemDTOS[0]' of bean class
[com.goitdev.datarender.command.domain.CreateTemplateCommand]: Illegal
attempt to get property 'labelItemDTOS' threw exception; nested exception
is org.springframework.beans.NullValueInNestedPathException: Invalid
property 'labelDTOS[0].labelItemDTOS' of bean class
[com.goitdev.datarender.command.domain.CreateTemplateCommand]: Could not
instantiate property type [com.goitdev.datarender.dto.domain.LabelItemDTO]
to auto-grow nested property path; nested exception is
java.lang.NoSuchMethodException:
com.goitdev.datarender.dto.domain.LabelItemDTO.<init>()
如果您尝试执行GET映射并打印出DTO的值,可以尝试以下操作: 在您的控制器方法中:
...
model.addAttribute("labelDTO", new LabelDTO());
...
在JSP中
...
<c:forEach items="${labelDTO.labelItemDTOS}" var="labelItemDTO">
<td>${labelItemDTO.value}<td>
<td>${labelItemDTO.placeHolder}<td>
<td>${labelItemDTO.newValue}<td>
</c:forEach>
...
或者对于POST see this question可能同样的问题。