第一种JSR303
引入
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
实体检查
one 1,2,3 逗号隔开的单个字符串
@NotEmpty(message = "channels can't null or empty")
@Pattern(regexp = "(?:(\\d|[1-2]\\d|3[0-2])(?:,|$))+", message = "invalid channels")
@ApiModelProperty(value = "设备通道,1开始.数字表示通道,0表示所有通道。用英文逗号间隔,此时的通道号操作都是对所有通道号一起操作", required = true)
private String channels;
two 不能为null
@NotNull(message = "streamType can't null")
three 数字范围
@Range(min = 1, max = 32, message = “channels must be 1~32”)
@Range(min = 1, max = 32, message = "channels must be 1~32")
@ApiModelProperty(value = "数字表示通道,设备通道,1开始", required = true)
private Long channel;
four 日期
先配置yml
spring:
jackson:
default-property-inclusion: non_null
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
deserialization:
adjust_dates_to_context_time_zone: true
@NotNull(message = "endTime can't be null")
// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "结束时间, yyyy-MM-dd HH:mm:ss", required = true)
private String endTime;
@Pattern(regexp = "\\d{4}-\\d{2}", message = "`beginDate` must format be `yyyy-MM`")
@ApiModelProperty(value = "查询的开始日期,格式 yyyy-MM", example = "2019-04")
private String beginDate;