0

我将 Springform 链接到对象(x = modelAttribute)。执行 POST 操作后,所有字段都保留其值。但是 (Multi-Select) list (items) 不保留其值。

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";
}

关于如何在发布后保持项目多选值的任何建议?

4

0 回答 0