我有以下控制器方法:
@RequestMapping(value = "/admin/addNewAdmin")
public String adminUsers(@ModelAttribute @Valid TerminalAdmin newAdmin, BindingResult bindingResult, ModelMap model, Principal principal, HttpSession session) {
if (bindingResult.hasErrors()) {
...
model.addAttribute("newAdmin",newAdmin);
return "admin/adminUsers";
}
....
}
和以下型号:
Entity
@Table(name = "terminal_admin")
public class TerminalAdmin {
.....
@Column(name = "email", nullable = false)
@Size(max = 255)
@NotEmpty
private String email;
}
jsp:
<form:form modelAttribute="newAdmin" action="/admin/addNewAdmin">
<div class="line">
<label for="">email</label>
<form:input path="email" type="text" name="emal" value=""/>
!!!<form:errors path="email" cssClass="error"/>!!!
<div class="clear"></div>
</div>
</form:form>
我在表格中输入空电子邮件
在控制器方法中的调试中,我看到bindingResult
电子邮件不应该为空的错误。
jsp 呈现为:
<form id="newAdmin" action="/admin/addNewAdmin" method="post">
<div class="line">
<label for="">email</label>
<input id="email" name="email" type="text" value="">
!!!!!!
<div class="clear"></div>
</div>
</form>