使用 ValidationApi 进行参数校验
导入依赖:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
实战:
import java.io.Serializable;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "分页服务请求")
public class PageRequest<T> implements Serializable {
@ApiModelProperty(value = "请求令牌")
private String token;
@ApiModelProperty(value = "每页大小")
@Min(value = 1, message = "分页大小不得小于1")
private int pageSize = 10;
@ApiModelProperty(value = "请求页数")
@Min(value = 1, message = "页码不得小于1")
private int page = 1;
@ApiModelProperty(value = "请求参数")
@NotNull(message = "params不能为空")
@Valid
private T params;
}
版权声明:本文为weixin_45521583原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。