打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
@NotEmpty、@NotNull、@NotBlank 的区别

@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。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
@NotEmpty、@NotBlank、@NotNull
Java-Bean Validation后端校验总结
常用校验注解@NotEmpty,@NotBlank,@NotNull,@Valid,@Validated用法区别,以及搭配 BindingResult使用,嵌套验证等
自定义注解解析器
java开源验证框架OVAL帮助文档
spring注解式参数校验
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服