天天看点

notempty注解属于哪个依赖_Spring注解 @NotBlank,@NotNull,@NotEmpty三者之间的区别

简述三者区别

@NotNull://CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0)。

@NotEmpty://CharSequence, Collection, Map 和 Array 对象不能是 null 并且相关对象的 size 大于 0。

@NotBlank://String 不能是 null 且去除两端空白字符后的长度(trimmed length)大于 0。

实例

String name = null;

@NotNull: false

@NotEmpty: false

@NotBlank: false

String name = “”;

@NotNull: true

@NotEmpty: false

@NotBlank: false

String name = " ";

@NotNull: true

@NotEmpty: true

@NotBlank: false

String name = “Great answer!”;

@NotNull: true

@NotEmpty: true

@NotBlank: true

参考:

https://www.cnblogs.com/xinruyi/p/11257663.html