Java annotation for Null but neither Empty nor Blank

后端 未结 5 678
别那么骄傲
别那么骄傲 2020-12-13 06:38

Is there are any java annotation(s) that can validate like the example below?

String test;
test = null; //valid
test = ""; //invalid
test = " &         


        
5条回答
  •  天命终不由人
    2020-12-13 06:59

    Did you try Hibernate-Validator? I think that's what you are looking for.

    import javax.validation.constraints.NotNull;
    
    import org.hibernate.validator.constraints.NotBlank;
    import org.hibernate.validator.constraints.NotEmpty;
    
    public class MyModel  {
    
        @NotNull
        private String  str1;
    
        @NotEmpty
        private String  str2;
    
        @NotBlank
        private String  str3;
    
    }
    

提交回复
热议问题