PageTemplate.java 1.99 KB
package com.diligrp.website.util.web;

import java.util.List;

import com.diligrp.website.util.dao.BaseQuery;

public class PageTemplate {

    public static PageTemplate create(BaseQuery bq, int totalSize, List<?> list) {

        PageTemplate template = new PageTemplate();

        template.setTotalSize(totalSize);
        template.setList(list);
        template.setPageSize(bq.getPageSize());
        template.setCurrPage(bq.getCurrPage());
        template.setQuery(bq);

        return template;
    }

    private BaseQuery query;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 总数量
     */
    private int totalSize;

    /**
     * 当前页
     */
    private int currPage;

    /**
     * 每页数量
     */
    private int pageSize;

    /**
     * 数据集合
     */
    private List<?> list;

    public int getTotalPage() {
        totalPage = totalSize / pageSize + (totalSize % pageSize > 0 ? 1 : 0);
        if (totalPage == 0) {
            totalPage = 1;
        }
        return totalPage;
    }

    public int getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(int totalSize) {
        this.totalSize = totalSize;
    }

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage;
    }

    public int getPageSize() {
        return pageSize;
    }

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

    public List<?> getList() {
        return list;
    }

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

    @Override
    public String toString() {
        return "PageTemplate [totalPage=" + totalPage + ", totalSize="
                + totalSize + ", currPage=" + currPage + ", pageSize="
                + pageSize + ", list=" + list + "]";
    }

    public BaseQuery getQuery() {
        return query;
    }

    public void setQuery(BaseQuery query) {
        this.query = query;
    }

}