关于spring:spring-validation

2次阅读

共计 697 个字符,预计需要花费 2 分钟才能阅读完成。

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 校验容器的元素个数

正文完
 0