我正在考虑使用实体Department
的CURD操作的Spring Web应用程序,这是处理新Department
的提交的处理程序:
@RequestMapping(value = "/", method = RequestMethod.POST)
public String addSubmit(@Valid Department department, BindingResult result,SessionStatus status) {
if (result.hasErrors()) {
return "department/add";
} else {
departmentService.save(department);
status.setComplete();
return "redirect:/departments/" + department.getId();
}
}
型号:
@Entity
public class Department extends BaseNamedEntity {
@NotNull
@NotEmpty
private String description;
...
}
形式:
<form:form method="post" action="${fmURL}" class="form-horizontal" commandName="department">
<form:hidden path="id"/>
<spring:bind path="name">
<div class="control-group ${status.error ? 'error' : ''}">
<label class="control-label">Name</label>
<div class="controls">
<form:input path="name"/>
<span class="help-inline">${status.errorMessage}</span>
</div>
</div>
</spring:bind>
<form:form>
但是,一旦我提交带有空字段的表单,通常应该显示errorMessage,相关的div
应该添加一个error
的类,但是我找不到错误消息。
发生了什么?
顺便说一下,这个例子来自Spring-petclinic project。