@NotEmpty
/**
* Asserts that the annotated string, collection, map or array is not {@code null} or empty.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
翻译过来是:断言,带注解的String,collection,map或数组不能为null,也不能为空。
也就是只对上述4种类型参数进行判断,判断条件:obj != null && obj.size() > 0。
@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
*/
翻译过来是:验证注释的String不是null或空的,与@NotEmpty的区别在于,尾部空格被忽略了(也就是说,纯空格的String也是不符合规则的)。
此注解只能用于验证String类型,判断条件:str != null && str.trim().size() > 0。
@NotNull
/**
* The annotated element must not be {@code null}.
* Accepts any type.
*
* @author Emmanuel Bernard
*/
翻译过来是:带注释的元素不能为null。接受任何类型。
它只判断是否是null。
最后
@NotNull:任何地方都可以用,但是它只判断是否是null
@NotEnpty:主要用于String,collection,map或数组,判断是否是null并且size>0
@NotBlank: 只用于String,会先个str执行trim(),再判断是否为null并且size>0