1.JSR303注解
<!--jsr 303-->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
注解 | 说明 |
---|---|
@Null | 被注释的元素必须为null |
@NotNull | 被注释的元素必须不为null |
@AssertFalse | 被注释的元素必须为false |
@AssertTrue | 被注释的元素必须为true |
@DecimalMax | 被标注的值必须不大于约束中指定的最大值. 这个约束的参数是一个通过BigDecimal定义的最大值的字符串表示.小数存在精度 |
@DecimalMin | 被标注的值必须不小于约束中指定的最小值. 这个约束的参数是一个通过BigDecimal定义的最小值的字符串表示.小数存在精度 |
@Digits | 验证 Number 和 String 的构成是否合法 |
@Email | 被注释的元素必须为电子邮箱地址 |
@Future | 被注释的元素必须为一个将来的日期 |
@FutureOrPresent | |
@Max | 被注释的元素必须为数字,值小于等于指定的最大值 |
@Min | 被注释的元素必须为数字,值大于等于指定的最小值 |
@Negative | 带注释的元素必须是严格的负数(0被认为是无效值。 |
@NegativeOrZero | 带注释的元素必须是负数或0 |
@NotBlank | Validate that the annotated string is not {@code null} or empty. The difference to {@code NotEmpty} is that trailing whitespaces are getting ignored |
@NotEmpty | Asserts that the annotated string, collection, map or array is not {@code null} or empty. |
@Past | 被注释的元素必须为一个过去的日期 |
@PastOrPresent | |
@Pattern | 被注释的元素必须符合指定的正则表达式 |
@Positive | 带注释的元素必须是严格正数(0被认为是无效值) |
@PositiveOrZero | 带注释的元素必须是正数或0 |
@Size | 被注释的元素大小必须在指定范围中 |
注 : 以上注解生效要配合@Valid
使用
- 当才华还配不上野心,就静下来学习
- blog地址:hangzhi.site