分页中的PageBean


import java.util.List;

public class PageBean {
    private List list;// 要返回某一页的记录列表
    private int allRow;// 总记录数
    private int totalPage;// 总页数
    private int currentPage;// 当前页
    private int pageSize;// 每页记录数
    private int count;// 页面显示的记录数

    private boolean isFirstPage;// 是否为第一页
    private boolean isLastPage;// 是否最后一页
    private boolean isPreviousPage;// 是否有前一页
    private boolean hasNextPage;// 是否有下一页

    private int id;

    public PageBean(int pageSize, int currentPage, int allRow, int totalPage, List list) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.allRow = allRow;
        this.totalPage = totalPage;
        this.list = list;
    }

    /**
     * @author 陈厚璋,新加的方法简化一个参数
     * @param pageSize
     * @param currentPage
     * @param allRow
     * @param list
     */
    public PageBean(int pageSize, int currentPage, int allRow, List list) {
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.allRow = allRow;
        this.totalPage = countTotalPage(pageSize, allRow);
        this.list = list;
        init();
    }

    public PageBean() {

    }

    public List getList() {
        return list;
    }

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

    public int getAllRow() {
        return allRow;
    }

    public void setAllRow(int allRow) {
        this.allRow = allRow;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        // if(pageSize * (currentPage - 1) + 1 == allRow) return currentPage -
        // 1;
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public boolean getIsFirstPage() {
        return currentPage == 1;
    }

    public void setFirstPage(boolean isFirstPage) {
        this.isFirstPage = isFirstPage;
    }

    public boolean isLastPage() {
        return currentPage == totalPage;
    }

    public void setLastPage(boolean isLastPage) {
        this.isLastPage = isLastPage;
    }

    public boolean getIsPreviousPage() {
        return (currentPage != 1 && currentPage != 0);
    }

    public void setPreviousPage(boolean isPreviousPage) {
        this.isPreviousPage = isPreviousPage;
    }

    public boolean isHasNextPage() {
        return currentPage != totalPage;
    }

    public boolean getHasNextPage() {
        return this.hasNextPage;
    }

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

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void init() {
        this.isFirstPage = getIsFirstPage();
        this.isLastPage = isLastPage();
        this.isPreviousPage = getIsPreviousPage();
        this.hasNextPage = isHasNextPage();
    }

    /**
     * 计算总页数
     * @param pageSize 每页记录数
     * @param allRow 总记录书
     * @return 总页数
     */
    public static int countTotalPage(final int pageSize, final int allRow) {
        int totalPage = (allRow + pageSize - 1) / pageSize;
        return totalPage;
    }

    /**
     * 计算当前页开始记录
     * @param pageSize 每页记录数
     * @param currentPage 当前第几页
     * @return 当前页开始记录号
     */
    public static int countOffset(final int pageSize, final int currentPage) {
        final int offset = pageSize * (currentPage - 1);

        return offset;
    }

    /**
     * 计算当前页,若为0或者请求的URL中没有page,则用1代替
     * @param page
     * @return
     */
    public static int countCurrentPage(int page) {
        final int curPage = (page == 0 ? 1 : page);
        return curPage;
    }

    /**
     * 得到某页显示的记录数的开始值为
     * @return
     */
    public int getCount() {
        if (currentPage < 1)
            currentPage = 1;
        return (currentPage - 1) * pageSize;
    }
}

你可能感兴趣的:(Java)