@NotNull和@NotEmpty和@NotBlank區別

  • 1.@NotNull:不能爲null,但能夠爲emptyhibernate

    (""," ","   ")
  • 2.@NotEmpty:不能爲null,並且長度必須大於0code

    (" ","  ")
  • 3.@NotBlank:只能做用在String上,不能爲null,並且調用trim()後,長度必須大於0get

    ("test")    即:必須有實際字符

*string

@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:io

    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

*參考連接:test

http://stackoverflow.com/questions/17137307/in-hibernate-validator-4-1-what-is-the-difference-between-notnull-notemptyobject

相關文章
相關標籤/搜索