@NotEmpty,NotNull和@NotBlank的區別


1.@NotNull:不能為null,但可以為empty
(""," "," ")

2.@NotEmpty:不能為null,而且長度必須大於0
(" "," ")

3.@NotBlank:只能作用在String上,不能為null,而且調用trim()后,長度必須大於0
("test") 即:必須有實際字符

*
@NotNull: The CharSequence, Collection, Map or Array object is not null,
but can be empty.

@NotEmpty: The CharSequence, Collection, Map or Array object is not null
and size > 0.

@NotBlank: The string is not null and the trimmed length is greater than
zero.

4.examples:
1.String name = null;

@NotNull: false
@NotEmpty:false
@NotBlank:false

2.String name = "";

@NotNull:true
@NotEmpty: false
@NotBlank: false

3.String name = " ";

@NotNull: true
@NotEmpty: true
@NotBlank: false

4.String name = "Great answer!";

@NotNull: true
@NotEmpty:true
@NotBlank:true


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM