java标准注解
Annotation | 注解说明 | 支持的数据类型 | null的返回值 | 额外的方法 | 备注 | |
---|---|---|---|---|---|---|
1 | DecimalMax | 元素必须是一个数字,其值必须小于或等于指定的最大值 | BigDecimal、BigInteger、CharSequence、byte、Byte、short、Short、int、Integer、long、Long | true | String value(); 元素的值必须小于等于value boolean inclusive() default true; 如果为true,元素的值必须小于等于value,否则元素的值必须小于value | |
2 | DecimalMin | 元素必须是一个数字,其值必须大于或等于指定的最小值 | BigDecimal、BigInteger、CharSequence、byte、Byte、short、Short、int、Integer、long、Long | true | String value(); 元素的值必须大于等于value boolean inclusive() default true; 如果为true,元素的值必须大于等于value,否则元素的值必须大于value | |
3 | Pattern | 必须与指定的正则表达式匹配 | CharSequence | true | String regexp(); 要匹配的正则表达式 Flag[] flags() default { }; 解析正则表达式时考虑的规则数组 | Flag包含: Pattern.UNIX_LINES 启用Unix行模式。 Pattern.CASE_INSENSITIVE 启用不区分大小写的匹配。 Pattern.COMMENTS 允许空格和模式注释 Pattern.MULTILINE 启用多行模式,改变^和$的行为 Pattern.DOTALL 启用dotall模式,此模式下’.'的匹配不受限制,可匹配任何字符,包括换行符 Pattern.UNICODE_CASE 启用支持Unicode的大小写折叠,启用此模式会影响性能 Pattern.CANON_EQ 启用Unicode字符的规范等价,启用此模式会影响性能 |
4 | 检查给定的字符序列(例如字符串)是否是格式正确的电子邮件地址 | CharSequence | true | String regexp() default “.*”; Pattern.Flag[] flags() default { }; | 注解参数值无效,不建议指定参数 | |
5 | Max | 元素必须是一个数字,其值必须小于或等于指定的最大值 | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long | true | long value(); 元素的值必须小于等于value | |
6 | Min | 元素必须是一个数字,其值必须大于或等于指定的最小值 | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long | true | long value(); 元素的值必须大于等于value | |
7 | AssertFalse | 元素的值必须为false | boolean、Boolean | true | 无 | |
8 | AssertTrue | 元素的值必须为true | boolean、Boolean | true | 无 | |
9 | Digits | 元素必须是可接受范围内的数字 | BigDecimal、BigInteger、CharSequence、byte、Byte、short、Short、int、Integer、long、Long | true | int integer(); 此数字接受的最大整数位数 int fraction(); 此数字接受的小数位数的最大数目 | |
10 | NegativeOrZero | 元素必须为负数或0 | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long、float、Float、double、Double | true | 无 | |
11 | Negative | 元素必须为严格的负数(即0视为无效值) | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long、float、Float、double、Double | true | 无 | |
12 | NotBlank | 删除任何前导或尾随空格后,检查字符序列是否不为空 | CharSequence | false | 无 | |
13 | NotEmpty | 元素必须不为null且不为empty | CharSequence、Collection、Map、Array | false | 无 | |
14 | NotNull | 元素必须不为null | Object | false | 无 | |
15 | Null | 元素必须为null | Object | true | 无 | |
16 | PositiveOrZero | 元素必须为正数或0 | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long、float、Float、double、Double | true | 无 | |
17 | Positive | 元素必须为严格的正数(即0视为无效值) | BigDecimal、BigInteger、byte、Byte、short、Short、int、Integer、long、Long、float、Float、double、Double | true | 无 | |
18 | Size | 元素大小必须在指定的边界(包括在内)之间。 | CharSequence、Collection、Map、Array | true | int min() default 0; 元素的大小必须大于或等于min int max() default Integer.MAX_VALUE; 元素的大小必须小于或等于max | |
19 | Future | 元素必须是将来的瞬间,日期或时间 | java.util.Date、java.util.Calendar、java.time.Instant、java.time.LocalDate、java.time.LocalDateTime、java.time.LocalTime、java.time.MonthDay、java.time.OffsetDateTime、java.time.OffsetTime、java.time.Year、java.time.YearMonth、java.time.ZonedDateTime、java.time.chrono.HijrahDate、java.time.chrono.JapaneseDate、java.time.chrono.MinguoDate、java.time.chrono.ThaiBuddhistDate | true | 无 | |
20 | FutureOrPresent | 元素必须是当前或将来的瞬间,日期或时间 | java.util.Date、java.util.Calendar、java.time.Instant、java.time.LocalDate、java.time.LocalDateTime、java.time.LocalTime、java.time.MonthDay、java.time.OffsetDateTime、java.time.OffsetTime、java.time.Year、java.time.YearMonth、java.time.ZonedDateTime、java.time.chrono.HijrahDate、java.time.chrono.JapaneseDate、java.time.chrono.MinguoDate、java.time.chrono.ThaiBuddhistDate | true | 无 | |
21 | Past | 元素必须是过去的瞬间,日期或时间 | java.util.Date、java.util.Calendar、java.time.Instant、java.time.LocalDate、java.time.LocalDateTime、java.time.LocalTime、java.time.MonthDay、java.time.OffsetDateTime、java.time.OffsetTime、java.time.Year、java.time.YearMonth、java.time.ZonedDateTime、java.time.chrono.HijrahDate、java.time.chrono.JapaneseDate、java.time.chrono.MinguoDate、java.time.chrono.ThaiBuddhistDate | true | 无 | |
22 | PastOrPresent | 元素必须是过去或现在的瞬间,日期或时间 | java.util.Date、java.util.Calendar、java.time.Instant、java.time.LocalDate、java.time.LocalDateTime、java.time.LocalTime、java.time.MonthDay、java.time.OffsetDateTime、java.time.OffsetTime、java.time.Year、java.time.YearMonth、java.time.ZonedDateTime、java.time.chrono.HijrahDate、java.time.chrono.JapaneseDate、java.time.chrono.MinguoDate、java.time.chrono.ThaiBuddhistDate | true | 无 |