| 注解 |
用法 |
适用类型 |
| @Null |
被注解的字段必须为空 |
|
| @NotNull |
被注解的字段必须不为空 |
|
| @NotBlank |
带注解的元素不能为null,并且必须至少包含一个非空白字符 |
|
| @NotEmpty |
带注解的元素不能为null也不能为空 |
String(长度)集合(大小)数组(长度) |
| @AssertTrue |
检查该字段必须为True |
Boolean |
| @AssertFalse |
检查该字段必须为False |
Boolean |
| @Min(value) |
被注解的字段必须大于等于指定的最小值 |
|
| @Max(value) |
被注解的字段必须小于等于指定的最大值 |
|
| @Negative |
带注解的元素必须是严格的负数(0被认为是无效值) |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @NegativeOrZero |
带注解的元素必须是严格的负数或0 |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @Positive |
带注解的元素必须是严格的正数(0被认为是无效值) |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @PositiveOrZero |
带注解的元素必须是严格的正数或0 |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @DecimalMin |
被注解的字段必须大于等于指定的最小值 |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @DecimalMax |
被注解的字段必须小于等于指定的最大值 |
BigDecimal,BigInteger,byte,short,int,long及其包装类 |
| @Size(min=,max=) |
被注解的字段的size必须在min和max之间,不需要判空 |
字符串、数组、集合 |
| @Digits(integer, fraction) |
被注解的字段必须在指定范围内,整数部分长度小于integer,小数部分长度小于fraction |
字符串、数组、集合 |
| @Past |
被注解的字段必须是一个过去的日期时间 |
|
| @PastOrPresent |
被注解的字段必须是过去的或现在的日期时间 |
|
| @Future |
被注解的字段必须是一个将来的日期时间 |
|
| @FutureOrPresent |
被注解的字段必须是现在的或将来的日期时间 |
|
| @Email |
字符串必须是格式正确的电子邮件地址 |
String |
| @Pattern(value) |
被注解的字段必须符合指定的正则表达式 |
|