The dbc4java framework supports constraints in the form of annotations placed on a field, method or class of a spring managed bean.
The list below lists all the built-in constraints.
| Constraint | Description | Example |
|---|---|---|
@AssertFalse |
The value of the field or property must be false |
@AssertFalseboolean supported; |
@AssertTrue |
The value of the field or property must be true |
@AssertTrueboolean supported; |
@DecimalMax |
The value of the field or property must be a decimal value lower than or equal to the number in the value element. Supported types are BigDecimal, BigInteger, String, byte, short, int, long, and their respective wrappers. Note that double and float are not supported due to rounding errors |
@DecimalMax("30.00")BigDecimal discount; |
@DecimalMin |
The value of the field or property must be a decimal value greater than or equal to the number in the value element. Supported types are BigDecimal, BigInteger, String, byte, short, int, long, and their respective wrappers. Note that double and float are not supported due to rounding errors |
@DecimalMin("5.00")BigDecimal discount; |
@Digits |
The value of the field or property must be a number within a specified range. The integer element specifies the maximum integral digits for the number, and the fraction element specifies the maximum fractional digits for the number. Supported types are BigDecimal, BigInteger, String, byte, short, int and their respective wrapper types. null elements are considered valid. |
@Digits(interger=2, fraction=2)BigDecimal price; |
@Email |
The value of the field or property must be a well-formed email address. | @EmailString emailAddress |
@Future |
The value of the field or property must be a date in the future. | @FutureDate eventDate; |
@Max |
The value of the field or property must be an integer value lower than or equal to the number in the value element | @Max(10)int quantity; |
@Min |
The value of the field or property must be an integer value greater than or equal to the number in the value element | @Min(5)int quantity; |
@NotBlank |
The value of the field or property must not be null or empty. The difference to @NotEmpty is that trailing whitespaces are getting ignored. |
@NotBlankString username; |
@NotEmpty |
The value of the annotated String, Collection, Map or array must not be null or empty. |
@NotEmptyString username; |
@NotNull |
The value of the field or property must not be null. |
@NotNullString userName; |
@Null |
The value of the field or property must be null. |
@NullObject unusedValue |
@Past |
The value of the field or property must be a date in the past | @PastDate birthday; |
@Pattern |
The value of the field or property must match the regular expression defined in the regexp element |
@Pattern(regexp="\\(\\d{3}\\)\\d{3}-\\d{4}")String phoneNumber; |
@Size |
The size of the field or property is evaluated and must match the specified boundaries. If the field or property is String, the size of the string is evaluated. If the field or property is a Collection, Map or array, the size of the entity is evaluated. Use one of the optional max or min elements to specify the boundaries |
@Size(min=2, max=10)String identifier; |
@URL |
The value of the field or property must be a valid URL. | @URLString url; |