Spring form:errors 不呈现
Spring form:errors doesn't render
我有以下控制器方法:
@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>
替换后工作
newAdmin
和
terminalAdmin
thx 这个
的第二点
我有以下控制器方法:
@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>
替换后工作
newAdmin
和
terminalAdmin
thx 这个
的第二点