@NotNull、@NotEmpty、@NotBlank

一、定义

@NotNull:不能为null,但可以为空(“”,“  ”,“     ”)

@NotEmpty:不能为null,如果为空串,长度要大于0(“ ”,“    ”)

@NotBlank:只能用于String,不能为null,且调用trim()去空格方法后长度也要大于0(“ABC    ”)

二、例子

String name = null

@NotNull:false

@NotEmpty:false

@NotBlank:false

 

String name = ""

@NotNull:true

@NotEmpty:false

@NotBlank:false

 

String name = " "

@NotNull:true

@NotEmpty:true

@NotBlank:false

 

String name = "zhangsan  lisi"

@NotNull:true

@NotEmpty:true

@NotBlank:true

posted @ 2020-10-15 10:30  积跬步丶行千里  阅读(333)  评论(0)    收藏  举报