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

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 +
            '}';
}

}

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

时间: 2024-08-25 23:51:18

个人常用工具类:分页工具类的相关文章

[C#] 常用工具类——文件操作类

/// <para> FilesUpload:工具方法:ASP.NET上传文件的方法</para> /// <para> FileExists:返回文件是否存在</para> /// <para> IsImgFilename:判断文件名是否为浏览器可以直接显示的图片文件名</para> /// <para> CopyFiles:复制指定目录的所有文件</para> /// <para> MoveFi

C#常用工具类——Excel操作类

/// 常用工具类——Excel操作类 /// <para> ------------------------------------------------</para> /// <para> CreateConnection:根据Excel文件路径和EXCEL驱动版本生成OleConnection对象实例</para> /// <para> ExecuteDataSet:执行一条SQL语句,返回一个DataSet对象</para>

[C#] 常用工具类——加密解密类

using System; using System.Configuration; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using S

常用cookie处理方法工具类

功能:cookie的添加.删除.获取值 1 import java.io.UnsupportedEncodingException; 2 import java.net.URLDecoder; 3 4 import javax.servlet.http.Cookie; 5 import javax.servlet.http.HttpServletRequest; 6 import javax.servlet.http.HttpServletResponse; 7 8 /** 9 * 常用cook

c#分页工具类,完美实现List分页

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProjectProgress.BLL { /// <summary> /// 分页工具类 /// </summary> /// <typeparam name="T"></typeparam> public class PagingUtil<T

.NET常用工具类——COOKIES操作类

using System;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Text;using System.Web;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.We

.Net常用工具类——Session操作类

using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts; namespace ZC

Java Web的分页工具类

最近写一个java web项目,以前分页的工具类,都是基础架构的人写好了的.也没有去细看,现在遇到这个状况. 就整理一下思路,自己写了一个分页的工具类.写的不好之处,还望斧正. 下面是我的代码: PageUtil.java 1 package util; 2 3 import java.util.Map; 4 5 /** 6 * 分页工具类 7 * @author lyh 8 * 9 */ 10 public class PageUtil { 11 private int total; //总数

C#常用工具类——Excel操作类(ZT)

本文转载于: http://www.cnblogs.com/zfanlong1314/p/3916047.html 1 /// 常用工具类——Excel操作类 2 /// <para> ------------------------------------------------</para> 3 /// <para> CreateConnection:根据Excel文件路径和EXCEL驱动版本生成OleConnection对象实例</para> 4 //