SPringle Validation是Spring提供的一个参数校验框架,使用预定义的注解完成参数校验。
一、自定义参数校验
1、引入Spring Valiation依赖
<!-- validation依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
2、参数前添加注解
表示字符串长度为5-16

3、Controller类添加@Validated注解

二、实体参数校验
1、实体类成员变量上添加注解
NotNull:值不能为null
NotEmpty:值不能为null,并且内容不为空
Email:满足邮箱格式


最低0.47元/天 解锁文章
972

被折叠的 条评论
为什么被折叠?



