@NotEmpty、@NotNull、@NotBlank 的区别
区别
2023-09-14 08:59:54 时间
@NotEmpty 用在集合上面(不能注释枚举)
@NotBlank用在String上面
@NotNull用在所有类型上面
1. @NotEmpty
Asserts that the annotated string, collection, map or array is not {@code null} or empty.
加了@NotEmpty的String类,Collection、Map、数组,是不能为null或者长度为0的(String、Collection、Map
的isEmpth()方法)
2. @NotBlank
Validate that the annotated string is not {@code null} or empty.
The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored.
“The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored.” –> 和{@code NotEmpty}不同的是,尾部空格被忽略,也就是说,纯空格的String也是不符合规则的。所以才会说@NotBlank用于String。
3.NotNull
The annotated element must not be {@code null}.
Accepts any type.
这个就很好理解了,不能为null。
相关文章
- CPLD和FPGA的区别(2)
- 服务器的系统和NAS有啥区别,nas和云服务器区别「建议收藏」
- hibernate和mybatisplus区别_Mybatis框架
- 大白话给你讲清楚面向对象编程和面向对象编程语言的区别与联系
- sql查询数据库中所有表名_使用权和所有权的区别
- PHP 函数传值和传引用的区别
- Select count(*)、Count(1)和Count(列)的区别及执行方式
- 浅谈MySQL和MariaDB区别(mariadb和mysql的性能比较)
- 浅谈RedisTemplate和StringRedisTemplate的区别
- Python super()使用注意事项(包含新式类和旧式类的区别)
- 、1>>和0>>的区别Linux 中2>>、1>>和0>>的区别(linux中2)
- 引领技术前沿Oracle代码大小写区别(Oracle代码大小写)
- Oracle中过程与函数的联系与区别(oracle中过程和函数)
- Oracle中Union与UnionAll的区别(适用多个数据库)
- javascript中apply和call方法的作用及区别说明