注解 | 含义 |
---|---|
@NotNull | 值不能为空 |
@Null | 值必须为空 |
@Pattern(regex=) | 字符串必须匹配正则表达式 |
@Size | 集合或者数组元素的数量必须在min和max之间 |
@CreditCardNumber(ignoreNonDigitCharacters=) | 字符串必须是信用卡号,按照美国的标准验证 |
字符串必须是Email格式 | |
@Length(min,max) | 校验字符串的长度 |
@NotBlank | 字符串不能为空串 |
@NotEmpty | 字符串不能为null,集合或者数组的size不能为空 |
@Range(min,max) | 数字必须大于min,小于max |
@SafeHtml | 字符串必须是安全的html |
@URL | 字符串必须是合法的URL地址 |
@AssertFalse | 值必须是false |
@AssertTrue | 值必须是true |
@DecimalMax(value=,inclusive=) | ( inclusive=true 小于等于 / inclusive =false 小于)值必须小于等于/小于指定的值,也可以注解在字符串类型的属性上 |
@DecimalMin(value=,inclusive=) | ( inclusive=true 大于等于 / inclusive =false 大于)值必须大于等于/大于指定的值,也可以注解在字符串类型的属性上 |
@Digist(integer=) | 数字格式检查。integer指定整数部分的最大长度,fraction指定小数部分的最大长度 |
@Future | 时间必须是未来的 |
@Past | 事件必须是过去的 |
@Max(vaue=) | 值必须小于等于value指定的值,不能注解在字符串类型的属性上 |
@Min(value=) | 值必须大于等于value指定的值,不能注解在字符串类型的属性上 |
@PositiveOrZero | 值必须为正整数或0 |
@Positive | 值必须为正整数 |
举例:
@ApiModelProperty("值")
@ApiModelProperty(value = "值类型(0:数字 1:字符串)", required = true, allowableValues = "0,1")
@NotNull(message = "[值]不能为空")
@NotBlank(message = "[值]不能为空")
@NotEmpty(message = "[值]不能为空")
@PositiveOrZero(message = "[值]必须是正整数")
@Min(value = 1, message = "[值]不能小于1")
@Max(value = 2, message = "[值]不能大于2")
@Size(max = 13,min=11, message = "[值]长度在11-13个字符之内")
@URL(message = "[值]URL网址不正确")
@Email(message = "[值]邮箱格式不正确")
@Pattern(regexp = "^1[0-9]{10}$",message = "[手机号]不合法")
@Pattern(regexp = "^男|女$", message = "[值]只能填写'男'或'女'")
@Pattern(regexp="/^(\\-|\\+)?(((\\d|[1-9]\\d|1[0-7]\\d|0{1,3})\\.\\d{0,6})|(\\d|[1-9]\\d|1[0-7]\\d|0{1,3})|180\\.0{0,6}|180)$/",message = "[值]地理经度不正确")
@Pattern(regexp = "/^(\\-|\\+)?([0-8]?\\d{1}\\.\\d{0,6}|90\\.0{0,6}|[0-8]?\\d{1}|90)$/",message = "[值]地理纬度不正确")
@Digits(integer = 9, fraction = 2, message = "[值]请保留2位小数")
@DecimalMin(value = "0.01", inclusive=true,message = "[值]必须大于等于0.01")
@DecimalMax(value = "999999999.99", inclusive=false,message = "[值]必须小于999999999.99")
@Past
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")