我有fiollowing控制器方法:
@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>
答案 0 :(得分:0)