The content searched online is roughly as follows:
@NotEmpty, @NotBlank, @NotNull in the verification box is still easy to mess up at first glance. The main usage status is recorded:
@NotEmpty is used on the collection class
@NotBlank Used on String
@NotNull is used on basic types
There are only simple results, but I can't find more specific content, so I went to the source code and found the following comments:
1. @NotEmpty
The code copy is as follows:
/**
* Asserts that the annotated string, collection, map or array is not {@code null} or empty.
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
In other words, the String class, Collection, Map, and array with @NotEmpty cannot be null or length 0 (String, Collection, Map isEmpty() method).
2. @NotBlank
The code copy is as follows:
/**
* Validate that the annotated string is not {@code null} or empty.
* The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored.
*
* @author Hardy Ferentschik
*/
“The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored.” >
Unlike {@code NotEmpty}, the tail space is ignored, that is, the pure space String does not conform to the rules. That's why I said @NotBlank is used for String.
3. @NotNull
The code copy is as follows:
/**
* The annotated element must not be {@code null}.
* Accepts any type.
*
* @author Emmanuel Bernard
*/
This is easy to understand, it cannot be null.