注册.jspx
<form action="register" id="user" method="POST">
<form:select path="factory">
<form:options itemValue="id" itemLabel="name" items="${factory}" />
</form:select>
</form>
模型
public class Factory {
@Size(max = 255)
private String name;
}
控制器
@RequestMapping(method = RequestMethod.POST, produces = "text/html",value = "/register")
public String UsersController.register(@Valid Users users,UserData userData,Factory factory,BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
Logger.getGlobal().log(Level.WARNING, bindingResult.getAllErrors().get(0).toString());
populateRegisterForm(uiModel, users);
return "userses/register";
}
uiModel.asMap().clear();
userData.setFactory(factory);
userData.persist();
users.setUserData(userData);
users.persist();
return "redirect:/userses/" + encodeUrlPathSegment(users.getId().toString(), httpServletRequest);
}
和html输出
<select>
<option value="1">aa</option>
<option value="2">bbbbbbbbbbbb</option>
</select>
选择标签在 html 输出中没有名称可验证。但我用 path="factory" 编辑了 jspx 文件