Java项目实战分页类

package com.utils;

import java.util.List;

/**
 * 分页实体类,保存当前分页状态变量
 *
 * @author
 */
public class Page {
    
    // 总行数
    private int rowCount;
    // 总页数
    private int pageCount;
    // 每页有多少行
    private int rowsPrePage=10;
    // 当前是第几页
    private int curPage;
    // 每页的开始记录
    private int beginIndex;
    // 是否有上页
    private boolean hasPrePage;
    // 是否有下页
    private boolean hasNextPage;
    //保存查询记录
    private List list;

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public Page() {
        
    }

    public Page(int curPage) {
        this.curPage = curPage;
    }

    /*
     * rows:总行数pageRows:每页行数
     */
    public void Init(int rows,int curPage) {
        Init(rows, 10, curPage);
    }

    public void Init(int rows, int pageRows,int curPage) {
        // 如果未设置当前页,默认为第一页
        if (curPage < 0 || curPage == 0) {
            curPage = 1;
        }

        // 得到总页数
        this.pageCount = rows / pageRows;
        if ((rows % pageRows) > 0) {
            this.pageCount += 1;
        }
        if (curPage > this.pageCount) {
            curPage = 1;
        }
        // 是否有上页
        if (this.curPage == 1) {
            this.hasPrePage = false;
        }
        // 是否有下页
        if (this.curPage == this.pageCount) {
            this.hasNextPage = false;
        }
        this.rowCount = rows;
        this.rowsPrePage = pageRows;
        this.beginIndex = (curPage - 1) * this.rowsPrePage;
        this.curPage = curPage;
    }

    public Page(int rowCount, int pageCount, int rowsPrePage, int curPage,
            int beginIndex, boolean hasPrePage, boolean hasNextPage) {
        this.rowCount = rowCount;
        this.pageCount = pageCount;
        this.rowsPrePage = rowsPrePage;
        this.beginIndex = beginIndex;
        this.curPage = curPage;
        this.hasNextPage = hasNextPage;
        this.hasPrePage = hasNextPage;
    }

    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int rowCount) {
        this.rowCount = rowCount;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getRowsPrePage() {
        return rowsPrePage;
    }

    public void setRowsPrePage(int rowsPrePage) {
        this.rowsPrePage = rowsPrePage;
    }

    public int getCurPage() {
        return curPage;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public int getBeginIndex() {
        return beginIndex;
    }

    public void setBeginIndex(int beginIndex) {
        this.beginIndex = beginIndex;
    }

    public boolean isHasPrePage() {
        return hasPrePage;
    }

    public void setHasPrePage(boolean hasPrePage) {
        this.hasPrePage = hasPrePage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值