首页 > 技术文章 > 弱校验之@NotNull@NotEmpty@NotBlank

zhucww 2020-07-13 14:50 原文

  • @NotNull
适用于非空判断
The annotated element must not be {@code null}.
CharSequence, Collection, Map 和 Array 对象不能是 null, 但可以是空集(size = 0)。  
  • @NotEmpty
适用于判断集合非空且有值
The annotated element must not be {@code null} nor empty. Supported 
CharSequence, Collection, Map 和 Array 对象不能是 null 并且相关对象的 size 大于 0。  
  • @NotBlank
适用于判断字符串非空且非空字符串
The annotated element must not be {@code null} and must contain at least one
non-whitespace character. Accepts {@code CharSequence}.
String 不是 null 且去除两端空白字符后的长度(trimmed length)大于 0。 

推荐阅读