Spring中@NotNull、@NotEmpty、@NotBlank和@PositiveOrZero等注解的使用


@NotNull
The annotated element must not be {@code null}.

校验参数一定不能为null,但是可以为" "。

@NotEmpty
The annotated element must not be {@code null} nor empty. Supported types are:
1、{@code CharSequence} (length of character sequence is evaluated);
2、{@code Collection} (collection size is evaluated);
3、{@code Map} (map size is evaluated);
4、Array (array length is evaluated);

校验集合类参数(如String类、Collection、Map、数据Array)不能为null或empty。其中String的length、Collection和Map的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,且不能是空字符串(" "),即调用trim()之后字符串的长度不能为0。

@PositiveOrZero
The annotated element must be a positive number or 0.

校验参数必须是正整数或0。