Validator common annotations

Insert picture description here

Rules:
@AssertFalse
Boolean, boolean
verify that the element value of the annotation is false
@AssertTrue
Boolean, boolean
verify that the element value of the annotation is true
@NotNull
any type
Verify that the element value of the annotation is not null
@Null
any type
Verify that the element value of the annotation is null
BigDecimal, BigInteger, byte, short, int, long, etc. Any Number or
@Min (value=value)
verification annotation element value is greater than or equal to the value specified by @Min
CharSequence (stored is a number) subtype
@Max (value=value)
Same as @Min requirement-
Verify that the element value of the annotation is less than or equal to the value specified by @Max
@DecimalMin(value=value) is the
same as the @Min requirement
Verify that the element value of the annotation is greater than or equal to the value specified by @ DecimalMin
@DecimalMax(value=value )
Same as @Min requirements,
verify that the element value of the annotation is less than or equal to the value specified by @ DecimalMax
@Digits(integer=integer digits, the
same as @Min requirements
Verify the number of integers and upper limit of the number of decimal places of the element value of the annotations
fraction=decimal number)
@Size(min='lower limit, max=upper limit)
string, Collection, Map, array, etc.
Verify that the element values ​​of the annotations are in min and max (including) within the specified interval, such as character length, set size
@Past
java.util.Date,java.util.Calendar; Date type of the Joda Time class library
Verify that the annotation element value (date type) is earlier than the current time
@ Future
is the same as @Past requirements.
Verify that the element value (date type) of the
annotation is later than the current time. Verify that the element value of the annotation is not empty (not null, and the length after removing the first space is 0). Different from @NotEmpty. @NotBlank only applies character string and
@NotBlank
CharSequence subtype
first space when compared removes string
@Length (min = lower limit, max =. the upper limit)
CharSequence subtype
verified annotation element value in the min and max length interval
the @NotEmpty
CharSequence sub Type, Collection, Map, Number
Verify that the element value of the annotation is not null and not empty (string length is not 0, collection size is not 0)
@Range(min=minimum, max=maximum)
BigDecimal, BigInteger, CharSequence, byte, short, int, long and other atomic types and packaging.
Verify that the element value of the annotation is between the minimum and maximum values.
Type
@Email(regexp=regular expression, flag=
CharSequence subtype (such as String)
The element value of the verification annotation is Email, and you can also specify a custom email format
flag pattern through regexp and flag )
@Pattern(regexp=regular expression, flag=
String. Any CharSequence subtype
verification annotation element value is the same as the specified The regular expression matching
flag pattern)
specifies the recursive verification of the associated objects; if there is an address object attribute in the user object, if you want to verify the address object together when verifying the user object, add any non-atomic type image to the address pair
@Valid @Valid annotation can cascade validation

Guess you like

Origin blog.csdn.net/qq_42910468/article/details/105344461