⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pageutil.java

📁 学习tapestry的好书啊,绝对经典实用.
💻 JAVA
字号:
package com.cucu.tapestry.util;

import java.io.Serializable;

/**
 * 一个查询相关的分页数据
 *
 * @author 绝情酷哥
 * @version 1.0
 */
public class PageUtil implements Serializable {
    /**
     * 当前第几页
     */
    int currentPageNum = 1;
    /**
     * 每页多少条记录
     */
    int perPageNum = 10; //默认每页10条记录
    /**
     * 总共有多少条记录,总记录数
     */
    int totalCount = 0;
    /**
     * 共有多少页*
     */
    int pageCount = 1;

    /**
     * @return 得到当前页码
     */
    public int getCurrentPageNum() {
        if (this.currentPageNum > this.pageCount) {
            this.currentPageNum = this.pageCount;
        } else if (this.currentPageNum < 1) {
            this.currentPageNum = 1;
        }
        return currentPageNum;
    }

    /**
     * 设置当前页码
     *
     * @param currentPageNum
     */
    public void setCurrentPageNum(int currentPageNum) {
        if (this.currentPageNum > this.pageCount) {
            this.currentPageNum = this.pageCount;
        } else if (this.currentPageNum < 1) {
            this.currentPageNum = 1;
        }
        this.currentPageNum = currentPageNum;
    }

    /**
     * @return 得到总记录数
     */
    public int getTotalCount() {
        return totalCount;
    }

    /**
     * 设置总记录数
     *
     * @param totalCount
     */
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        this.doPageBreak();
    }

    /**
     * @return 得到每页记录数
     */
    public int getPerPageNum() {
        return perPageNum;
    }

    /**
     * 设置每页记录数
     *
     * @param perPageNum
     */
    public void setPerPageNum(int perPageNum) {
        this.perPageNum = perPageNum;
        doPageBreak();
    }

    /**
     * @return 返回总页码数
     */
    public int getPageCount() {
        return pageCount;
    }

    /**
     * 计算分页的总页数
     */
    public void doPageBreak() {
        if (this.perPageNum > 0 && this.totalCount > 0) {
            this.pageCount =
                    (int) Math.ceil(
                            ((double) this.totalCount) / ((double) this.perPageNum));
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -