@NotNull 主要用在基本类型上,不能为null
@NotEmpty 主要用在集合类上面,不能为null,并且长度必须大于0
@NotBlank 只可以用在String上面,只能作用在String上,不能为null,而且调用trim()后,长度必须大于0
看下边这个例子就很好理解了:
1.String name = null; @NotNull: false @NotEmpty:false @NotBlank:false 2.String name = ""; @NotNull:true @NotEmpty: false @NotBlank: false 3.String name = " "; @NotNull: true @NotEmpty: true @NotBlank: false 4.String name = "Hello world!"; @NotNull: true @NotEmpty:true @NotBlank:true
以上是自己的个人理解,如果有错误,欢迎批评指正,感谢感谢!