简单的Java分页工具类 - 极悦
首页 课程 师资 教程 报名

简单的Java分页工具类

  • 2021-10-21 10:23:13
  • 989次 极悦

Java开发工具有很多, Java分页工具类只是其中之一。

import java.util.List;
/**
* Paging tool
 * @author Administrator
 *
 */
public class PageBean<T> {
private int pageNo = 1; //Current page
private int pageSize = 4; //Number of pages per page
private int totalCount; //Total number of records
private int totalPages; //Total pages--read only
private List<T> pageList; //The collection generic type corresponding to each page
    public int getPageNo() {
        return pageNo;
    }
//The current page number cannot be less than 1 and cannot be greater than the total number of pages
    public void setPageNo(int pageNo) {
        if(pageNo<1)
            this.pageNo = 1;
        else if(pageNo > totalPages)
            this.pageNo = totalPages;
        else
            this.pageNo = pageNo;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
//The total number of records determines the total number of pages
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        this.totalPages = (this.totalCount%this.pageSize==0)?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
    }
    public int getTotalCount() {
        return totalCount;
    }
//Read only
    public int getTotalPages() {
        return totalPages;
    }
    public List<T> getPageList() {
        return pageList;
    }
    public void setPageList(List<T> pageList) {
        this.pageList = pageList;
    }
    public PageBean(int pageNo, int pageSize, int totalCount, int totalPages,
            List<T> pageList) {
        super();
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPages = totalPages;
        this.pageList = pageList;
    }
    public PageBean() {
        super();
        // TODO Auto-generated constructor stub
    }
}

mysql 分页:select * from table limit (pageNo-1)*pageSize,pageSize;

oracle分页:select a.* (select table.*,rowum rn from table) a where rn>(pageNo-1)*pageSize and rn <=pageNo*pageSize;

这是最简单的分页工具之一。

选你想看

你适合学Java吗?4大专业测评方法

代码逻辑 吸收能力 技术学习能力 综合素质

先测评确定适合在学习

在线申请免费测试名额
价值1998元实验班免费学
姓名
手机
提交