本文中使用的个软件版本(见最下方截图):
Spring:4.1.1
JSR 303 Validator: 1.0.0
JSR 303 Validator实现:hibernate 4.3.2
说明:为什么这里选择hibernate 4.3.2,而没有选择更高版本?
原因:Hibernate Validator 4.X 版本是完全基于JSR303;5.X版本还实现了JSR349的特性。
What’s the difference between Hibernate Validator 3, 4 and 5?
Hibernate Validator 3.x and 4.x/5.x are different codebases.
Hibernate Validator is the original validation framework from the Hibernate team and is now referred to as "Legacy Hibernate Validator".
Hibernate Validator 4.x is the reference implementation of Bean Validation 1.0 (JSR 303),while Hibernate Validator 5.x is the reference implementation of Bean Validation 1.1 (JSR 349). Active development happens on the 5.x codebase.
一、使用Hibernate Validator内置的国际化消息配置
1. 引入所需要的包
2. 配置
<mvc:annotation-driven />
3. 在需要验证的对象属性字段上用注解校验
<pre name="code" class="java">public class Application {
privat