当前位置:网站首页>JRS-303用法
JRS-303用法
2022-07-27 16:00:00 【StrugglingXuYang】
项目中用到数据校验了,网上搜了些资料,整理下 方便自己查阅
JRS-303 是做数据校验的
导入依赖
<!--JSR-303数据校验开始-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!--JSR-303数据校验结束-->
首先在实体类上添加 @Validated 注解 如下图
@Validated
public class Collect implements Serializable {
private static final long serialVersionUID = 851224694046130732L;
以下是常用的注解,在字段上方标注即可
空检查
@Null 验证对象是否为null
@NotNull 验证对象是否不为null, 无法查检长度为0的字符串
@NotBlank 检查约束字符串是不是Null还有被Trim的长度是否大于0,只对字符串,且会去掉前后空格.
@NotEmpty 检查约束元素是否为NULL或者是EMPTY.
Booelan检查
@AssertTrue 验证 Boolean 对象是否为 true
@AssertFalse 验证 Boolean 对象是否为 false
长度检查
@Size(min=, max=) 验证对象(Array,Collection,Map,String)长度是否在给定的范围之内
@Length(min=, max=) Validates that the annotated string is between min and max included.
日期检查
@Past 验证 Date 和 Calendar 对象是否在当前时间之前,验证成立的话被注释的元素一定是一个过去的日期
@Future 验证 Date 和 Calendar 对象是否在当前时间之后 ,验证成立的话被注释的元素一定是一个将来的日期
@Pattern 验证 String 对象是否符合正则表达式的规则,被注释的元素符合制定的正则表达式,regexp:正则表达式 flags: 指定 Pattern.Flag 的数组,表示正则表达式的相关选项。
数值检查
@Min 验证 Number 和 String 对象是否大等于指定的值
@Max 验证 Number 和 String 对象是否小等于指定的值
@DecimalMax 被标注的值必须不大于约束中指定的最大值. 这个约束的参数是一个通过BigDecimal定义的最大值的字符串表示.小数存在精度
@DecimalMin 被标注的值必须不小于约束中指定的最小值. 这个约束的参数是一个通过BigDecimal定义的最小值的字符串表示.小数存在精度
@Digits 验证 Number 和 String 的构成是否合法
@Digits(integer=,fraction=) 验证字符串是否是符合指定格式的数字,interger指定整数精度,fraction指定小数精度。
@Range(min=, max=) 被指定的元素必须在合适的范围内
@Range(min=10000,max=50000,message=”range.bean.wage”)
@Email 验证是否是邮件地址,如果为null,不进行验证,算通过验证。
边栏推荐
- ts学习笔记-interface
- fragmentTransaction.replace第二个参数报错
- XStream reports an error abstractreflectionconverter$unknownfield exception when parsing XML
- @Scheduled and quartz
- 知物由学 | APP大瘦身,新一代AAB框架下的安全加固之道
- Backup table recovery table
- 【学习笔记】数据库中锁的分类
- 类的六大关系——依赖和关联的区别
- 2022 safety officer-a certificate examination questions and online simulation examination
- Six relationships of classes -- the difference between dependency and Association
猜你喜欢

Personal understanding of convolution calculation process of convolution neural network

Big gap? Requirements and conditions for candidates with different academic qualifications to take the postgraduate entrance examination

The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation

The global cloud market is growing rapidly, and data security has entered a strong regulatory era of rule of law
知物由学 | SO加固如何提升Android应用的安全性?

2022 high altitude installation, maintenance and removal of test question simulation test platform operation

In the fourth week of July, Yidun business risk control focused on the supreme law to regulate app's forcible request for personal information

卷积神经网络——FPN(Feature Pyramid Networks)介绍

施耐德电气、欧莱雅等企业巨头如何开放式创新?DEMO WORLD世界创新峰会揭秘

Resolve merge fields in salesforce
随机推荐
面试常见问题一二
[introduction to database system (Wang Shan)] Chapter 1 - Introduction
TCP connection status identification (syn, fin, ACK, PSH, RST, urg)
In the fourth week of July, Yidun business risk control focused on the supreme law to regulate app's forcible request for personal information
Prevent SQL injection
Convolutional neural network -- Introduction to FPN (feature pyramid networks)
工信部再治数据安全,网易易盾“隐私合规”守住企业经营底线
6月第1周易盾业务风控关注 | 新东方学而思等15家机构被顶格罚款
查找表中多余重复记录并删除保留最小一个
hutool- 数组工具
Wechat applet realizes location map display and introduces map map without navigation
golang chan实现互斥锁
【Codeforces】 B. Make it Divisible by 25
机器学习之评价指标(二)——分类评价指标
Six relationships of classes -- the difference between dependency and Association
Multi thread import data and generate error files for redis storage
【云图说】 第249期 移动应用安全服务—App的体检中心,全面检测,安全上路!
Kubernetes 1.24 high availability cluster binary deployment
jpa连接数据库password字段BLOB
Multi thread implementation loop