Integers are widely used in most applications. When these variables are persisted, it is useful to be able to limit their values to a specific range. The @Min and @Max annotations are used for this purpose.
We will use the LicenseBean
and LicenseBeanFacade
classes from the ValidationApplication
as discussed in the Validating persistent fields and properties recipe.
The size of an integer field can also be validated using the @Min and @Max annotations. The monthsToExpire
field in the following declaration must have a value between 12 and 48 inclusive to avoid a constraint violation.
@Min(12) @Max(48) private int monthsToExpire;
The @Min or @Max annotations can be used without the other one. In such situations, there is no lower or upper bound depending on which annotation is not used.
13.58.51.36