Spring Common Forms validation annotations

Source: Internet
Author: User
Tags wrappers

The following are the main validation notes and explanations:

Annotations

Applicable data types

Description

@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

@DecimalMax (value=x)

BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive. Additionally supported by Hv:any sub-type of number andcharsequence.

Verifies that the element value of the annotation is less than or equal to the value specified by @ Decimalmax

@DecimalMin (value=x)

BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive. Additionally supported by Hv:any sub-type of number andcharsequence.

Verifies that the element value of the annotation is less than or equal to the value specified by @ decimalmin

@Digits (integer= integer digits, fraction= decimal place)

BigDecimal, BigInteger, String, byte,short, int, long and the respective wrappers of the primitive. Additionally supported by Hv:any sub-type of number andcharsequence.

To verify the integer and maximum number of decimal digits for the element value of the annotation

@Future

Java.util.Date, Java.util.Calendar; Additionally supported by HV, if Thejoda time Date/time API was on the class Path:any implementations ofreadablepartial an Dreadableinstant.

Verify that the annotation's element value (date type) is later than the current time

@Max (value=x)

BigDecimal, BigInteger, Byte, Short,int, long and the respective wrappers of the primitive types. Additionally supported by Hv:any sub-type ofcharsequence (the numeric value represented by the character sequence is eval uated), any sub-type of number.

Verifies that the element value of the annotation is less than or equal to the value specified by @max

@Min (value=x)

BigDecimal, BigInteger, Byte, Short,int, long and the respective wrappers of the primitive types. Additionally supported by Hv:any sub-type of charsequence (the numeric value represented by the char sequence is evaluate d), any sub-type of number.

Verifies that the element value of the annotation is greater than or equal to the value specified by @min

@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

@Past

Java.util.Date, Java.util.Calendar; Additionally supported by HV, if Thejoda time Date/time API was on the class Path:any implementations ofreadablepartial an Dreadableinstant.

Verify that the annotation's element value (date type) is earlier than the current time

@Pattern (regex= Regular expression, flag=)

String. Additionally supported by Hv:any sub-type of Charsequence.

Validates that the element value of the annotation matches the specified regular expression

@Size (min= min, max= max)

String, Collection, Map and arrays. Additionally supported by Hv:any sub-type of Charsequence.

Verifies that the element value of the annotation is within a specified interval of min and max (inclusive), such as character length, collection size

@Valid

Any non-primitive type (reference type)

Validates the associated object, such as an order object in the account object, specifying the validation order object

@NotEmpty

CharSequence,Collection,Map and Arrays

Verifies that the element value of the annotation is not null and is not empty (string length is not 0, collection size is not 0)

@Range (min= min, max= max)

CharSequence, Collection, Map and Arrays,BigDecimal, BigInteger, CharSequence, byte, short, int, long and the respective wrappers of the primitive types

Verifies that the element value of the annotation is between the minimum and maximum values

@NotBlank

CharSequence

Verifies that the element value of the annotation is not null (NOT NULL, the first space is removed after the length is 0), differs from @notempty, @NotBlank is applied only to strings and the whitespace is stripped of the string when compared

@Length (min= lower limit, max= upper limit)

CharSequence

Validates the element value length of annotations within min and Max intervals

@Email

CharSequence

Verify that the element value of the annotation is email, or you can specify a custom email format via regular expressions and flag

Spring Common Forms validation annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.