簡述三者差別
@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