码迷,mamicode.com
首页 > 其他好文 > 详细

个人常用工具类:分页工具类

时间:2019-07-18 13:52:08      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:long   tostring   getc   记录   current   port   nal   oid   data   

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

// 分页工具类

public class PageBean implements Serializable {

private static final long serialVersionUID = -8741766802354222579L;

private int pageSize = 5; // 每页显示多少条记录

private int currentPage = 1; //当前第几页数据

private int totalRecord; // 一共多少条记录

private int totalPage; // 一共多少页记录

private List<T> dataList; //要显示的数据


public PageBean(int pageNum, int pageSize, List<T> sourceList) {
    if (sourceList == null || sourceList.isEmpty()) {
        return;
    }
    // 总记录条数
    this.totalRecord = sourceList.size();
    // 每页显示多少条记录
    this.pageSize = pageSize;
    //获取总页数
    this.totalPage = this.totalRecord / this.pageSize;
    if (this.totalRecord % this.pageSize != 0) {
        this.totalPage = this.totalPage + 1;
    }

    // 当前第几页数据
    this.currentPage = this.totalPage < pageNum ? this.totalPage : pageNum;

    // 起始索引
    int fromIndex = this.pageSize * (this.currentPage - 1);

    // 结束索引

    int toIndex = this.pageSize * this.currentPage > this.totalRecord ? this.totalRecord : this.pageSize * this.currentPage;

    this.dataList = sourceList.subList(fromIndex, toIndex);
}


public PageBean() {

}


public PageBean(int pageSize, int currentPage, int totalRecord, int totalPage, List<T> dataList) {
    super();
    this.pageSize = pageSize;
    this.currentPage = currentPage;
    this.totalRecord = totalRecord;
    this.totalPage = totalPage;
    this.dataList = dataList;
}


public int getPageSize() {
    return pageSize;
}


public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
}


public int getCurrentPage() {
    return currentPage;
}


public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
}


public int getTotalRecord() {
    return totalRecord;
}


public void setTotalRecord(int totalRecord) {
    this.totalRecord = totalRecord;
}


public int getTotalPage() {
    return totalPage;
}


public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
}


public List<T> getDataList() {
    return dataList;
}


public void setDataList(List<T> dataList) {
    this.dataList = dataList;
}


@Override


public String toString() {
    return "PageBean{" +
            "pageSize=" + pageSize +
            ", currentPage=" + currentPage +
            ", totalRecord=" + totalRecord +
            ", totalPage=" + totalPage +
            ", dataList=" + dataList +
            '}';
}

}

个人常用工具类:分页工具类

标签:long   tostring   getc   记录   current   port   nal   oid   data   

原文地址:https://www.cnblogs.com/jiang4yu/p/11206626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!