https://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/
另参见
http://docs.oracle.com/javaee/7/api/javax/validation/constraints/package-summary.html
Annotation | Part of Bean Validation Specification | Apply on | Use | Hibernate Metadata impact |
---|---|---|---|---|
@AssertFalse | yes | field/property | check that the annotated element is false . | none |
@AssertTrue | yes | field/property | check that the annotated element is true . | none |
@DecimalMax | yes | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | The annotated element must be a number whose value must be lower or equal to the specified maximum. The parameter value is the string representation of the max value according to theBigDecimal string representation. | none |
@DecimalMin | yes | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | The annotated element must be a number whose value must be higher or equal to the specified minimum. The parameter value is the string representation of the min value according to theBigDecimal string representation. | none |
@Digits(integer=, fraction=) | yes | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | Check whether the property is a number having up to integer digits and fraction fractional digits. | Define column precision and scale. |
no | field/property. Needs to be a string. | Check whether the specified string is a valid email address. | none | |
@Future | yes | field/property. Supported types are java.util.Date andjava.util.Calendar . | Checks whether the annotated date is in the future. | none |
@Length(min=, max=) | no | field/property. Needs to be a string. | Validate that the annotated string is between min and max included. | none |
@Max | yes | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | Checks whether the annotated value is less than or equal to the specified maximum. | Add a check constraint on the column. |
@Min | yes | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | Check whether the annotated value is higher than or equal to the specified minimum. | Add a check constraint on the column. |
@NotNull | yes | field/property | Check that the annotated value is not null. | Column(s) are not null. |
@NotEmpty | no | field/property. Needs to be a string. | Check if the string is not null nor empty. | none |
@Null | yes | field/property | Check that the annotated value is null. | none |
@Past | yes | field/property. Supported types are java.util.Date andjava.util.Calendar . | Checks whether the annotated date is in the past. | none |
@Pattern(regex=, flag=) | yes | field/property. Needs to be a string. | Check if the annotated string match the regular expressionregex . | none |
@Range(min=, max=) | no | field/property. Supported types are BigDecimal ,BigInteger , String ,byte , short , int , long and the respective wrappers of the primitive types. | Check whether the annotated value lies between (inclusive) the specified minimum and maximum. | none |
@Size(min=, max=) | yes | field/property. Supported types are String , Collection ,Map and arrays . | Check if the annotated element size is between min and max (inclusive). | Column length will be set to max. |
@Valid | yes | field/property | Perform validation recursively on the associated object. | none |