JSP 不显示验证错误
JSP doesn't display validation errors
<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;
}
}
它应该工作得很好!
确保路径中的 "aDepartment" 指的是 "ADepartment" Class.
中名为 "aDepartment" 的属性
<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;
}
}
它应该工作得很好! 确保路径中的 "aDepartment" 指的是 "ADepartment" Class.
中名为 "aDepartment" 的属性