<spring:bind path="aDepartment">
<div class="form-group ${status.error ? 'has-error' : ''}">
<label class="col-lg-4 control-label">Department *</label>
<div class="col-lg-8">
<form:input class="form-control" path="aDepartment" required="true"
placeholder="Department" />
<form:errors path="aDepartment" class="control-label" />
</div>
</div>
</spring:bind>
PATH是当前页面的路径。 当我违反验证规则(故意)时,错误不会绑定到模型,并且jsp不会显示错误。 我应该手动将错误绑定到模型吗?如果是这样我该怎么办?
@RequestMapping(value = "/admin/adepartement/add", method = RequestMethod.POST)
public String add(
@ModelAttribute(value = "addadepartment") @Valid ADepartment pADepartment,
final BindingResult pBindingResult, final ModelMap pModel) {
if (!pBindingResult.hasErrors()) {
///
}
}else{
return PATH;
}
}
答案 0 :(得分:1)
它应该工作得很好! 确保&#34; aDepartment&#34;在路径中引用一个名为&#34; aDepartment&#34;的属性。在你的&#34; ADepartment&#34;类。