NotNull、NotEmpty、NotBlank 的区别

@NotNull

The CharSequence, Collection, Map or Array object is not null, but can be empty.

@NotEmpty

The CharSequence, Collection, Map or Array object is not null and size > 0.

@NotBlank

The string is not null and the trimmed length is greater than zero.

Here are a few examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 = "Great answer!";
@NotNull: true
@NotEmpty: true
@NotBlank: true