All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.remliyx.dbeasy.utils.page.PagerUtils Maven / Gradle / Ivy

There is a newer version: 2.0.0-RELEASE
Show newest version
package top.remliyx.dbeasy.utils.page;

import java.io.Serializable;
import java.util.List;

/**
 * 文件说明:分页工具类
 * 创建作者: 李宜栩
 * 创建日期: 2023-4-24
 * 版权所有:lyx
 * 版本:    Version 1.0
 */
public class PagerUtils implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 4542617637761955078L;

    /**
     * currentPage 当前页
     */
    private int currentPage = 1;
    /**
     * pageSize 每页大小
     */
    private int pageSize = 100;
    /**
     * pageTotal 总页数
     */
    private int pageTotal;
    /**
     * recordTotal 总条数
     */
    private int recordTotal = 0;
    /**
     * previousPage 前一页
     */
    private int previousPage;
    /**
     * nextPage 下一页
     */
    private int nextPage;
    /**
     * firstPage 第一页
     */
    private int firstPage = 1;
    /**
     * lastPage 最后一页
     */
    private int lastPage;

    /**
     * content 每页的内容
     */
    private List content;

    public PagerUtils(int currentPage, int pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
    }

    /**
     * 获取起始偏移量
     *
     * @return 偏移量
     */
    public int fromIndex() {
        return (pageSize * (currentPage - 1));
    }

    /**
     * 获取结束偏移量
     *
     * @return 结束偏移量
     */
    public int toIndex() {
        return pageSize * currentPage > getRecordTotal() ? getRecordTotal() : (pageSize * currentPage);
    }

    // 以下set方式是需要赋值的

    /**
     * 设置当前页 
* * @param currentPage * @author kangxu */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } /** * 设置每页大小,也可以不用赋值,默认大小为10条
* * @param pageSize * @author kangxu */ public void setPageSize(int pageSize) { this.pageSize = pageSize; } /** * 设置总条数,默认为0
* * @param recordTotal * @author kangxu */ public void setRecordTotal(int recordTotal) { this.recordTotal = recordTotal; otherAttr(); } /** * 设置分页内容
* * @param content * @author kangxu */ public void setContent(List content) { this.content = content; } /** * 设置其他参数 * * @author kangxu */ public void otherAttr() { // 总页数 this.pageTotal = this.recordTotal % this.pageSize > 0 ? this.recordTotal / this.pageSize + 1 : this.recordTotal / this.pageSize; // 第一页 this.firstPage = 1; // 最后一页 this.lastPage = this.pageTotal; // 前一页 if (this.currentPage > 1) { this.previousPage = this.currentPage - 1; } else { this.previousPage = this.firstPage; } // 下一页 if (this.currentPage < this.lastPage) { this.nextPage = this.currentPage + 1; } else { this.nextPage = this.lastPage; } } // 放开私有属性 public int getCurrentPage() { return currentPage; } public int getPageSize() { return pageSize; } public int getPageTotal() { return pageTotal; } public int getRecordTotal() { return recordTotal; } public int getPreviousPage() { return previousPage; } public int getNextPage() { return nextPage; } public int getFirstPage() { return firstPage; } public int getLastPage() { return lastPage; } public List getContent() { return content; } @Override public String toString() { return "Pager [currentPage=" + currentPage + ", pageSize=" + pageSize + ", pageTotal=" + pageTotal + ", recordTotal=" + recordTotal + ", previousPage=" + previousPage + ", nextPage=" + nextPage + ", firstPage=" + firstPage + ", lastPage=" + lastPage + ", content=" + content + "]"; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy