package org.bulkframework.common.pagination;

import java.io.Serializable;
import java.util.List;

/**
 * 分页处理类.
 * 
 * @author wiflish
 * @createTime 2012-5-31 下午5:07:00
 */
public class Pager<T> implements Serializable {
    private static final long serialVersionUID = -7813513436632328774L;

    private int totalCount;
    /** 页大小,默认20条记录. */
    private int pageSize = 20;
    /** 当前页, 默认第一页 */
    private int pageNo = 1;
    private List<T> pageData;

    public Pager() {
    }

    public Pager(int pageNo, int pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    /**
     * 获取当前页的记录开始索引.
     * 
     * @return
     */
    public int getStartIndex() {
        return (pageNo - 1) * pageSize;
    }

    /**
     * 获取当前页的记录结尾索引.
     * 
     * @return
     */
    public int getEndIndex() {
        return pageNo * pageSize;
    }

    /**
     * 计算总页数.
     * 
     * @return
     */
    public int getPageCount() {
        if (totalCount <= 0) {
            return 0;
        }
        return (totalCount - 1) / pageSize + 1;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getPageSize() {
        return pageSize;
    }

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

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public List<T> getPageData() {
        return pageData;
    }

    public void setPageData(List<T> pageData) {
        this.pageData = pageData;
    }
}

@@ -430,32 +430,150 @@
     
-private List%3CT%3E pageData
+%0A    /**%0A     * %E5%BD%93%E5%89%8D%E9%A1%B5%E6%95%B0%E6%8D%AE.%0A     */%0A    private List%3CT%3E pageData;%0A    %0A    /**%0A     * %E6%98%AF%E5%90%A6%E9%9C%80%E8%A6%81%E6%9F%A5%E8%AF%A2%E6%80%BB%E8%AE%B0%E5%BD%95%E6%95%B0.%0A     */%0A    private boolean needTotalCount = true
 ;%0A%0A 
@@ -662,30 +662,50 @@
 is.pageNo = 
+(
 pageNo
+ %3C= 0 ? 1 : pageNo)
 ;%0A        th
@@ -714,32 +714,33 @@
 .pageSize = 
+(
 pageSize
 ;%0A    %7D%0A%0A   
@@ -719,32 +719,283 @@
 Size = (pageSize
+ %3C= 0 ? 20 : pageSize);%0A    %7D%0A%0A    public Pager(int pageNo, int pageSize, boolean needTotalCount) %7B%0A        this.pageNo = (pageNo %3C= 0 ? 1 : pageNo);%0A        this.pageSize = (pageSize %3C= 0 ? 20 : pageSize);%0A        this.needTotalCount = needTotalCount
 ;%0A    %7D%0A%0A    /**
@@ -1753,24 +1753,25 @@
 eSize = 
+(
 pageSize
 ;%0A    %7D%0A
@@ -1754,32 +1754,54 @@
 Size = (pageSize
+ %3C= 0 ? 20 : pageSize)
 ;%0A    %7D%0A%0A    pub
@@ -1914,22 +1914,42 @@
 ageNo = 
+(
 pageNo
+ %3C= 0 ? 1 : pageNo)
 ;%0A    %7D%0A
@@ -2103,11 +2103,202 @@
 a;%0A    %7D
+%0A%0A    public boolean isNeedTotalCount() %7B%0A        return needTotalCount;%0A    %7D%0A%0A    public void setNeedTotalCount(boolean needTotalCount) %7B%0A        this.needTotalCount = needTotalCount;%0A    %7D
 %0A%7D%0A

优化分页对象.