12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package com.example.common;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.github.pagehelper.PageInfo;
- import io.swagger.v3.oas.annotations.media.Schema;
- import lombok.Data;
- import java.util.List;
- /**
- * 分页返回对象
- */
- @Data
- public class PageVo<T> {
- @Schema(description = "总记录数")
- private Long totalCount;
- @Schema(description = "每页记录数")
- private Long pageSize;
- @Schema(description = "总页数")
- private Long totalPage;
- @Schema(description = "当前页数")
- private Long currPage;
- @Schema(description = "列表数据")
- private List<T> list;
- public PageVo(List<T> list, Page page) {
- this.list = list;
- this.totalCount = page.getTotal();
- this.pageSize = page.getSize();
- this.currPage = page.getCurrent();
- this.totalPage = page.getPages();
- }
- /**
- * 分页
- *
- * @param list 列表数据
- * @param totalCount 总记录数
- * @param pageSize 每页记录数
- * @param currPage 当前页数
- */
- public PageVo(List<T> list, int totalCount, int pageSize, int currPage) {
- this.list = list;
- this.totalCount = (long) totalCount;
- this.pageSize = (long) pageSize;
- this.currPage = (long) currPage;
- this.totalPage = (long) Math.ceil((double) totalCount / pageSize);
- }
- public PageVo(PageInfo pageInfo) {
- this.list = pageInfo.getList();
- this.totalCount = pageInfo.getTotal();
- this.pageSize = (long) pageInfo.getPageSize();
- this.currPage = (long) pageInfo.getPageNum();
- this.totalPage = (long) pageInfo.getPages();
- }
- public PageVo(List<T> list) {
- this.list = list;
- }
- }
|