如题,开发中很容易混淆而导致逻辑出错
1、@NotNull:不能为null,但可以为empty(如””)。
2、@NotEmpty:不能为null,而且长度必须大于0
3、@NotBlank:只能作用在String上,不能为null,而且调用trim()后,长度必须大于0
实例:
A、String username = null;
@NotNull: false
@NotEmpty: false
@NotBlank: false
B、String name = “”;
@NotNull: true
@NotEmpty: false
@NotBlank: false
C、String name = ” “;
@NotNull: true
@NotEmpty: true
@NotBlank: false
D、String name = “Hello World!!!”;
@NotNull: true
@NotEmpty: true
@NotBlank: true
| null | 空字符串(“”) | 空白字符(空格、制表符) |
| isEmpty | true | true | false |
| isNotEmpty | false | false | true |
| isBlank | true | true | true |
| isNotBlank | false | false | false |