@NotNull
: The value cannot be null;@NotEmpty
: The value of a string, collection or array cannot be empty, that is, the length is greater than 0;@NotBlank
: The value of the string cannot be blank, that is, it cannot contain only spaces;@Size
: Whether the size of the string, collection or array is within the specified range;@Min
: The minimum value of the value;@Max
: The maximum value of the value;@DecimalMin
: The minimum value of a numerical value, which can include decimals;@DecimalMax
: The maximum value of a numerical value, which can include decimals;@Digits
: Whether the value meets the specified integer and decimal places;@Pattern
: Whether the string matches the specified regular expression;@Email
: Whether the string is a valid email address;@AssertTrue
: Whether the Boolean value is true;@AssertFalse
: Whether the Boolean value is false;@Future
: Whether the date is in the future;@Past
: Whether the date is in the past;
like:
@NotBlank(message = "User name cannot be blank")
1 private String name;
@NotBlank(message = "Password cannot be blank")
@Size(min = 6, message = "The password length cannot be less than 6 characters")
2 private String password;
@Min(value = 0, message = "Age cannot be less than 0 years old")
@Max(value = 1120, message = "Age should not exceed 120 years old")
3private Integer age;
@Pattern(regexp = "^((13[0-9])|(15[^4])|(18[0-9])|(17[0-9])|(147))\d{ 8}$", message = "Mobile phone number format is incorrect")
4 private String phone;