如果是spring boot项目,一定要在pom.xml文件中引入以下依赖包:<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
package com.gdss.ruralrevitalization.model;
import lombok.Data;
import javax.validation.constraints.Max;
//分页实体类
@Data
public class PageModel {
@Max(value = 1)
private int current; //当前页
@Max(value = 100)
private int size; //数量
}
Controller类,通过BindingResult查看是否有报错信息,需要写在@Valid参数后面
@GetMapping("/getList")
public ResultModel getList(@Valid PageModel page,BindingResult result){
ResultModel resultModel=new ResultModel();
IPage<UserViewBaseModel> lstEntity =administrativeAreasService.getListPage(searchModel,new Page(page.getCurrent(), page.getSize()));
resultModel.setData(lstEntity);
return resultModel;
}
[
本帖最后由 xiexie 于 2023-2-8 13:31 编辑 ]