我有一个register.jsp
页面,其中我将以下数据绑定到modelAttribute userform
。Spring将数据从JSP绑定到控制器
<form:form method="post" modelAttribute="userform"
enctype="multipart/form-data" autocomplete="off" class="form">
<spring:bind path="firstName">
<label>First Name: </label>
<form:input path="firstName" placeholder="First Name" />
</spring:bind>
<spring:bind path="lastName">
<label class="control-label">Last Name: </label>
<form:input path="lastName" placeholder="Last Name" />
</spring:bind>
</form:form>
哪里得到和控制器上岗位的方法是:
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String register(@ModelAttribute("userform") Employee employee, Model model) {
List<Role> roleList = roleService.getAllList();
model.addAttribute("roleList", roleList);
model.addAttribute("userform", employee);
return "employee/register";
}
@RequestMapping(value = { "/register" }, method = RequestMethod.POST)
public String processRegistration(@Valid @ModelAttribute("userform") Employee employee, BindingResult result,
Model model, HttpServletRequest request) throws IllegalStateException, IOException {
//(expecting the data from jsp) nothing in the employeee object :(
//dosomething
return "employee/register";
}
虽然我已经使用相同的名称userform
和实体Employee
属性名称是完全一样的,我无法获得将数据从JSP形成到控制器。我一定在这里做错了事,但找不到它。任何帮助,将不胜感激。
什么版本的春天你使用? – Dev
@Dev 4.1.6.Release – Sujan