专注Java教育14年 全国咨询/投诉热线:444-1124-454
星辉LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 简单的Java分页工具类

简单的Java分页工具类

更新时间:2021-10-21 10:23:13 来源:星辉 浏览876次

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;

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

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>