@ NotNull, @ NotEmpty, @ NotBlank difference

 Sample results:

// null
String name = null;
@NotNull: false
@NotEmpty: false
@NotBlank: false
 
// empty string 
String name = "" ;
@NotNull: true
@NotEmpty: false
@NotBlank: false
 
// space 
String name = "" ;
@NotNull: true
@NotEmpty: true
@NotBlank: false
 
// string 
String name = "liudehua" ;
@NotNull: true
@NotEmpty: true
@NotBlank: true

 

Between the three types outlined under fair use:

@NotNull: CharSequence, Collection, the Map Array, and is not null, but may be an empty set (size = 0). 

The @NotEmpty: CharSequence, Collection, the Map and Array can not be null, and the need to size> 0. 

@NotBlank: String is not null, and the length (trimmed length) after removal of whitespace characters ends is greater than 0.

 

Source:

  • @NotNull:

Can not be null, but can be empty, there is no constraint Size

  • @NotEmpty:

Can not be null, and Size> 0

  • @NotBlank:

 Only after a String, and can not be null trim () size> 0



 

Guess you like

Origin www.cnblogs.com/lwcode6/p/11910755.html