使用 ValidationApi 进行参数校验

使用 ValidationApi 进行参数校验

导入依赖:

		<dependency>
			<groupId>javax.validationgroupId>
			<artifactId>validation-apiartifactId>
			<version>2.0.1.Finalversion>
		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;
}

你可能感兴趣的:(#,java-常用工具类,java,spring)