请求参数nodeQueryParam继承PageBean
public class PageBean {
@ApiModelProperty(value = "页码",example = "1")
private Integer pageNum=1;
@ApiModelProperty(value = "每页数量",example = "10")
private Integer pageSize=10;
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}
返回的result
public class MeshPage {
private int pageNum;
private int pageSize;
private int pages;
private int total;
private List<?> pageList;
}
分页工具
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.PageUtil;
public class MeshPageUtil {
public static int totalPage(int totalCount, int pageSize) {
return PageUtil.totalPage(totalCount, pageSize);
}
public static MeshPage getPageDto(List<?> list, int pageNum, int pageSize) {
MeshPage meshPage = new MeshPage();
if (list == null) {
return meshPage;
}
int pages = PageUtil.totalPage(list.size(), pageSize);
List pageList = ListUtil.page(pageNum, pageSize, list);
meshPage.setPageSize(pageSize);
meshPage.setPageNum(pageNum);
meshPage.setPages(pages);
meshPage.setTotal(list.size());
meshPage.setPageList(pageList);
return meshPage;
}
}
使用方式
public Result queryService(@RequestBody NodeQueryParam nodeQueryParam) {
# 首先查询出所有的结果
List<PodInfoIpPort> podInfoIpPorts = meshNodeService.managerNode(nodeQueryParam);
#计算数据合
int total = podInfoIpPorts.size();
#计算分页页数,前端可传getPageSize
int pages = MeshPageUtil.totalPage(total, nodeQueryParam.getPageSize());
#分页结果
MeshPage mesh = MeshPageUtil.getPageDto(podInfoIpPorts, nodeQueryParam.getPageNum(), nodeQueryParam.getPageSize());
mesh.setPages(pages);
return Result.success(mesh);
}