从springboot-2.3
开始,校验包被独立成了一个starter
组件,所以须要引入如下依赖:
<!--校验组件--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId></dependency><!--web组件--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency>
而springboot-2.3
之前的版本只须要引入 web 依赖就能够了。
@AssertFalse 必须是false
@AssertTrue 必须是true
@DecimalMax 小于等于给定的值
@DecimalMin 大于等于给定的值
@Digits 可设定最大整数位数和最大小数位数
@Email 校验是否合乎Email格局
@Future 必须是未来的工夫
@FutureOrPresent 以后或未来工夫
@Max 最大值
@Min 最小值
@Negative 正数(不包含0)
@NegativeOrZero 正数或0
@NotBlank 不为null并且蕴含至多一个非空白字符
@NotEmpty 不为null并且不为空
@NotNull 不为null
@Null 为null
@Past 必须是过来的工夫
@PastOrPresent 必须是过来的工夫,蕴含当初
@PositiveOrZero 负数或0
@Size 校验容器的元素个数