@NotBlank注解地正确使用

作者: 紫霞等了至尊宝五百年 | 来源:发表于2018-05-08 00:23 被阅读1130次
  • @NotNull:不能为null,但可以为empty
  • @NotEmpty:不能为null,而且长度必须大于0
    @NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度必须大于0
    案例:
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

注意在使用@NotBlank等注解时,一定要和@valid一起使用,不然@NotBlank不起作用



相关文章

网友评论

    本文标题:@NotBlank注解地正确使用

    本文链接:https://www.haomeiwen.com/subject/kmgbrftx.html