javeWeb中实现分页器效果工具类

javeWeb中实现分页器效果工具类

package com.guwenren.bean;

/**
 * 分页页码计算类
 * @author guwenren
 *
 */
public class PageIndex {
    private long startindex;
    private long endindex;

    public PageIndex(long startindex, long endindex) {
        this.startindex = startindex;
        this.endindex = endindex;
    }

    public long getStartindex() {
        return startindex;
    }

    public void setStartindex(long startindex) {
        this.startindex = startindex;
    }

    public long getEndindex() {
        return endindex;
    }

    public void setEndindex(long endindex) {
        this.endindex = endindex;
    }

    public static PageIndex getPageIndex(long viewpagecount, int currentPage,
            long totalpage) {
        long startpage = currentPage
                - (viewpagecount % 2 == 0 ? viewpagecount / 2 - 1
                        : viewpagecount / 2);
        long endpage = currentPage + viewpagecount / 2;
        if (startpage < 1) {
            startpage = 1;
            if (totalpage >= viewpagecount)
                endpage = viewpagecount;
            else
                endpage = totalpage;
        }
        if (endpage > totalpage) {
            endpage = totalpage;
            if ((endpage - viewpagecount) > 0)
                startpage = endpage - viewpagecount + 1;
            else
                startpage = 1;
        }
        return new PageIndex(startpage, endpage);
    }
}

转载
来源

你可能感兴趣的:(javaWeb)