@ NotEmpty, @ NotBlank, @ NotNull, @ notempty @ notblank

Source: Internet
Author: User

@ NotEmpty, @ NotBlank, @ NotNull, @ notempty @ notblank

@ NotEmpty used on the Collection class

@ NotBlank: Used on String

@ NotNull is used in basic types

 

 


Only simple results, but more specific content cannot be found, so I went to the source code and found the following annotations:

 

1. @ NotEmpty

/** 
* Asserts that the annotated string, collection, map or array is not {@code null} or empty. 
* 
* @author Emmanuel Bernard 
* @author Hardy Ferentschik 
*/

That is to say, the String class, Collection, Map, and array added with @ NotEmpty cannot be null or the length is 0 (the isEmpty () method of String, Collection, and Map ).

2. @ NotBlank

/** 
* 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}, trailing spaces are ignored. That is, strings with pure spaces do not comply with the rules. So it is said that @ NotBlank is used for String.

3. @ NotNull

/** 
* The annotated element must not be {@code null}. 
* Accepts any type. 
* 
* @author Emmanuel Bernard 
*/

This is easy to understand and cannot be null.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.