Hibernate驗證器不顯示錯誤消息。我錯過了什麼?請參閱下面的代碼。休眠驗證器不顯示錯誤消息
這裏是一個依賴:
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
而且實體註釋列:從控制器
@Entity
@Table(name = "transport")
public class Transport {
....
@NotEmpty
@Column(name = "name")
private String name;
....
}
這裏有方法:
//show all and add form
@RequestMapping (value = "/admin/transports", method = RequestMethod.GET)
public String findAll(ModelMap map){
List<Transport> transports = transportService.findAll();
map.put("transport", new Transport());
map.put("transports", transports);
return "admin/transports/list";
}
//add new
@RequestMapping(value = "/admin/transport/add", method = RequestMethod.POST)
public String addTypeShop(@ModelAttribute("type") @Valid Transport transport, BindingResult result) {
if (result.hasErrors()) {
return "redirect:/admin/transports";
} else {
this.transportService.addTransport(transport);
return "redirect:/admin/transports";
}
}
和JSP頁面:
<form:form role="form" action="/admin/transport/add" method="post" commandName="transport">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="name">Name</label>
<form:input type="text" path="name" class="form-control input-sm" id="name" autofocus="true"/>
<form:errors path="name"/>
</div>
</div>
<input type="submit" class="btn btn-sm btn-primary" value="Add" onclick="loading()"/>
</form:form>
你不在任何地方調用驗證器。在這裏看到這個教程:http://hibernate.org/validator/documentation/getting-started/。 – Tom 2014-11-01 15:14:40
驗證工作,只是不顯示錯誤消息 – user3127896 2014-11-01 15:54:23