@NotEmpty 用在集合类上面 @NotBlank 用在String上面 @NotNull 用在基本类型上 只有简单的结果,但是再更具体一点的内容就搜不到了,所以去看了看源码,发现了如下的注释: 1. @NotEmpty /** * Asserts that the annotated string, collection, map or array is not {@code null} or empty. * * @author Emmanuel Bernard * @author…
@interface NotNull The annotated element must not be {@code null}.Accepts any type.-------------------- @interface NotEmpty * The annotated element must not be {@code null} nor empty. Supported types are:* <ul>* <li>{@code CharSequence} (lengt…
1. 三者主要区别如下: @NotEmpty :用于集合类,不能为null,且size>0 @NotNull:不能为null,但可以为empty,没有size的约束 @NotBlank:只用于String,不能为null,且trim()之后size>0 2. 通过查看源码注释如下: @NotEmpty /** * Asserts that the annotated string, collection, map or array is not {@code null} or empty. *…
@NotEmpty 用在集合上面(不能注释枚举) @NotBlank用在String上面 @NotNull用在所有类型上面 1. @NotEmpty Asserts that the annotated string, collection, map or array is not {@code null} or empty. 加了@NotEmpty的String类,Collection.Map.数组,是不能为null或者长度为0的(String.Collection.Map 的isEmpth(…
源码解析 @NotEmpty根据JDK源码注释说明,该注解只能应用于char可读序列(可简单理解为String对象),colleaction,map,array上,因为该注解要求的是对象不为null且size>0,所以只有上述对象是拥有size属性的,而Integer,Long等基础对象包装类没有该属性 /** * The annotated element must not be {@code null} nor empty. Supported types are: * <ul> *…
@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,…