You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
j2ee1/src/main/java/com/utils/PageUtils.java

102 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.utils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.Page;
/**
* 分页工具类,用于处理分页相关的数据和操作。
*/
public class PageUtils implements Serializable {
private static final long serialVersionUID = 1L; // 序列化版本号
// 总记录数
private long total;
// 每页记录数
private int pageSize;
// 总页数
private long totalPage;
// 当前页数
private int currPage;
// 列表数据
private List<?> list;
/**
* 构造函数,通过传入的列表数据、总记录数、每页记录数和当前页数进行初始化。
* @param list 列表数据
* @param totalCount 总记录数
* @param pageSize 每页记录数
* @param currPage 当前页数
*/
public PageUtils(List<?> list, int totalCount, int pageSize, int currPage) {
this.list = list;
this.total = totalCount;
this.pageSize = pageSize;
this.currPage = currPage;
this.totalPage = (int)Math.ceil((double)totalCount/pageSize); // 计算总页数
}
/**
* 构造函数通过MyBatis Plus的Page对象进行初始化。
* @param page MyBatis Plus的Page对象
*/
public PageUtils(Page<?> page) {
this.list = page.getRecords(); // 获取当前页的数据列表
this.total = page.getTotal(); // 获取总记录数
this.pageSize = page.getSize(); // 获取每页记录数
this.currPage = page.getCurrent(); // 获取当前页码
this.totalPage = page.getPages(); // 获取总页数
}
/**
* 构造函数通过传入的参数Map进行初始化。
* @param params 包含分页参数的Map对象
*/
public PageUtils(Map<String, Object> params) {
Page page =new Query(params).getPage(); // 根据参数创建Page对象
new PageUtils(page); // 调用另一个构造函数进行初始化
}
// Getter和Setter方法
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public List<?> getList() {
return list;
}
public void setList(List<?> list) {
this.list = list;
}
public long getTotalPage() {
return totalPage;
}
public void setTotalPage(long totalPage) {
this.totalPage = totalPage;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
}