@NotEmpty 用在集合类上面 

@NotBlank 用在String上面 

@NotNull 用在基本类型上


只有简单的结果,但是再更具体一点的内容就搜不到了,所以去看了看源码,发现了如下的注释:

1. @NotEmpty

/** 
* Asserts that the annotated string, collection, map or array is not {@code null} or empty. 

* @author Emmanuel Bernard 
* @author Hardy Ferentschik 
*/

也就是说,加了@NotEmpty的String类、Collection、Map、数组,是不能为null或者长度为0的(String、Collection、Map的isEmpty()方法)。

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. 

* @author Hardy Ferentschik 
*/

“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. 

* @author Emmanuel Bernard 
*/

这个就很好理解了,不能为null。

@NotEmpty、@NotBlank、@NotNull的区别的更多相关文章

  1. hibernate validate验证框架中@NotEmpty、@NotbBank、@NotNull的区别

    Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull 的区别 Hibernate Validator验证框架中@NotEmpty.@NotBlank ...

  2. @NotNull @NotEmpty @NotBlank区别

    @interface NotNull The annotated element must not be {@code null}.Accepts any type.----------------- ...

  3. @NotEmpty、@NotNull 和 @NotBlank 的区别

    1. 三者主要区别如下: @NotEmpty :用于集合类,不能为null,且size>0 @NotNull:不能为null,但可以为empty,没有size的约束 @NotBlank:只用于S ...

  4. Hibernate Validator验证框架中@NotEmpty、@NotBlank、@NotNull 的区别

    Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull的主要使用情况 @NotEmpty  用在集合类上面 @NotBlank   用在String上 ...

  5. @NotEmpty、@NotNull、@NotBlank 的区别

    @NotEmpty 用在集合上面(不能注释枚举) @NotBlank用在String上面 @NotNull用在所有类型上面 1. @NotEmpty Asserts that the annotate ...

  6. @NotEmpty、@NotNull、@NotBlank注解解析

    源码解析 @NotEmpty根据JDK源码注释说明,该注解只能应用于char可读序列(可简单理解为String对象),colleaction,map,array上,因为该注解要求的是对象不为null且 ...

  7. 注解@NotNull/@NotEmpty/@NotBlank

    @NotNull:不能为null,但可以为empty @NotEmpty:不能为null,而且长度必须大于0 @NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度 ...

  8. 弱校验之@NotNull@NotEmpty@NotBlank

    @NotNull 适用于非空判断 The annotated element must not be {@code null}. CharSequence, Collection, Map 和 Arr ...

  9. Spring 中@NotNull, @NotEmpty和@NotBlank之间的区别是什么?

    简述三者区别 @NotNull://CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0). @NotEmpty://Ch ...

随机推荐

  1. Cracking the Coding Interview 题目分析笔记—— Array and String

    1.Determine if a string has all unique characters learn: 为了减少空间利用率,其比较优秀的算法一般都适用位操作 返回值的命名方法,我们需要学习 ...

  2. KD-tree详解

    转载自:http://blog.csdn.NET/zhjchengfeng5/article/details/7855241 首先来一个问题: 给定平面上一个点集 E ,还有一个定点 V ,怎么在一群 ...

  3. Keepalived实现双机热备

    第一步.安装.网上很多源码安装的步骤.咱们这里以最快的方式 . [Shell] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 ...

  4. Linux 配置Jenkins

    一.安装包下载: 1. jdk-8u152-linux-x64.tar.gz下载: wget http://download.oracle.com/otn-pub/java/jdk/8u152-b16 ...

  5. 用nodejs把目录下所有用px做单位的css文件转化为用rem做单位的css文件

    20171105 1211/星期日 公司为了更好适配手机端,以前用px做单位的css文件,全部需要转化为用rem做单位,目前是1rem=37.5px;开发新项目时,还是用习惯的px写样式代码,完成UI ...

  6. window.setInterval与window.setTimeout使用实例

    <script type="text/javascript"> var arrived = false; var num = 0; var timer = window ...

  7. C#中的Explicit和Implicit

    今天在Review一个老项目的时候,看到一段奇怪的代码. if (dto.Payment == null) continue; var entity = entries.FirstOrDefault( ...

  8. 升级安装php7要考虑的几个方面

    php7从推出到现在,前两天官方已经发布到7.2版本,把自己升级和安装php7中遇到的问题和解决方法做一个笔记,内容主要包括:1) mysql2) php3) nginx4) memcache扩展5) ...

  9. Javascript实现简单的下拉二级菜单

    在线演示;http://jsfiddle.net/Web_Code/ThhbG/embedded/result/ <span style="font-size:14px;"& ...

  10. JAVA入门--目录

    在此记录自己的JAVA入门笔记,备忘 JAVA入门[1]--安装JDK JAVA入门[2]-安装Maven JAVA入门[3]—Spring依赖注入 JAVA入门[4]-IntelliJ IDEA配置 ...