<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
如找不到依赖 加上版本
1、给需要检验的字段加上校验注解 并定义自己的校验提示 例: @NotBlank (message=“xxx")
2、在controller提交参数前 加上@Valid 开启校验
javax.validation.constraints包下的
@NotNull
@NotEmpty 不能为空或者空串
只能接受map 数组 集合等等 不能接受Integer Long。。。
@NotBlank 必须包含一个非空的字符
@Future 将来的时间
@Max 最大值
@Mix 最小值
@Size 长度
@Email 标注的字段必须是一个邮箱
@Pattern(regexp ="正则表达式")
org.hibernate.validator.constraints包下的
@URL
![](https://i-blog.csdnimg.cn/blog_migrate/6902917ad28aaa9b3fd801adb4724ba5.jpeg)