今天在做单元测试的时候发现pojo里的@NotNull没有起作用, 然后做了一些查询, 记录一下.
In Spring 3, you can enable “mvc:annotation-driven” to supportJSR303 bean validationvia@Validannotation, if any JSR 303 validator framework on the classpath.
Note
Hibernate Validator is the reference implementation for JSR 303
@Valid和@NotNull是JSR 303这个标准集成在spring里面的, 但是spring本身并没有对这些annotation实现解释器, 需要集成一个hibernate-validator对其进行解析.
参考: http://www.mkyong.com/spring-mvc/spring-3-mvc-and-jsr303-valid-example/
网友评论