侧边栏壁纸
博主头像
会飞的大象博主等级

爱运动的程序猿

  • 累计撰写 126 篇文章
  • 累计创建 158 个标签
  • 累计收到 0 条评论
标签搜索

目 录CONTENT

文章目录

@NotBlank 注解的正确使用

会飞的大象
2021-04-15 / 0 评论 / 0 点赞 / 1,122 阅读 / 0 字

@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不起作用
image.png

image.png

0

评论区