我将Springform链接到对象(x = modelAttribute)。执行POST操作后,所有字段都保持其值。但是(多选)列表(项目)并没有保留其值。
X班级:
class x
{
String a;
String b;
List<Y> items;
}
JSP:
<form:form method="post" path="x" modelAttribute="role">
<form:input path="a" type="text" />
<form:input path="b" type="text" />
<form:options items="${mylist}" path="items" itemValue="id" itemLabel="name" />
</form:form>
控制器:
@RequestMapping(value = "/case/new", method = RequestMethod.GET)
public String newRole(ModelMap model)
{
if(!model.containsAttribute("x")){
model.addAttribute("x", new X());
}
return "/roles/newRole";
}
@RequestMapping(value = "/case/new", method = RequestMethod.POST)
public String doNewCase(@ModelAttribute("x") @Validated X x ,BindingResult bindingResult,ModelMap model)
{
if (bindingResult.hasErrors()) {
if(!model.containsAttribute("x")){
model.addAttribute("x", new X());
}
return "cases/newCase";
}
caseService.addNewCase(x);
return "cases/list";
}
关于如何保留项目值的任何建议?发布后多选?