package org.treeleafj.xmax.bean;

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

/**
 * 分页结果
 *
 * @Author leaf
 * 2015/10/12 0012 22:30.
 */
public class PageResult<T> implements Serializable {

    private Pageable pageable;

    /**
     * 查出来的数据
     */
    private List<T> list;

    /**
     * 总条数
     */
    private long total;

    public PageResult() {
    }

    /**
     * 构造分页查询结果对象
     *
     * @param pageable 分页请求
     * @param list     查询的结果数据
     */
    public PageResult(Pageable pageable, List<T> list) {
        this(pageable, list, Long.valueOf(String.valueOf(list.size())));
    }

    /**
     * 构造分页查询结果对象
     *
     * @param pageable 分页请求
     * @param list     查询的结果数据
     * @param total    总条数
     */
    public PageResult(Pageable pageable, List<T> list, long total) {
        this.pageable = pageable;
        this.list = list;
        this.total = total;
    }

    /**
     * 构造分页查询结果对象
     *
     * @param pageNo   页码
     * @param pageSize 每页大小
     * @param list     查询的结果数据
     */
    public PageResult(int pageNo, int pageSize, List<T> list) {
        this(new Pageable(pageNo, pageSize), list);
    }

    /**
     * 构造分页查询结果对象
     *
     * @param pageNo   页码
     * @param pageSize 每页大小
     * @param list     查询的结果数据
     * @param total    总条数
     */
    public PageResult(int pageNo, int pageSize, List<T> list, long total) {
        this(new Pageable(pageNo, pageSize), list, total);
    }

    /**
     * 获取当前页码
     *
     * @return
     */
    public int getPageNo() {
        return this.pageable.getPageNo();
    }

    /**
     * 获取总分页数
     *
     * @return
     */
    public long getTotalPage() {
        long l = total / this.pageable.getPageSize();
        return total % this.pageable.getPageSize() == 0 ? l : l + 1;
    }

    /**
     * 获取每页大小
     *
     * @return
     */
    public int getPageSize() {
        return this.pageable.getPageSize();
    }

    /**
     * 获取起始偏移量(从0开始)
     *
     * @return
     */
    public int getOffset() {
        return this.pageable.getOffset();
    }

    /**
     * 获取数据
     *
     * @return
     */
    public List<T> getList() {
        return list;
    }

    public long getTotal() {
        return total;
    }

    public Pageable getPageable() {
        return pageable;
    }

    public PageResult setPageable(Pageable pageable) {
        this.pageable = pageable;
        return this;
    }

    public PageResult setList(List<T> list) {
        this.list = list;
        return this;
    }

    public PageResult setTotal(long total) {
        this.total = total;
        return this;
    }
}

@@ -1445,138 +1445,8 @@
  %7D%0A%0A
-    /**%0A     * %E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E9%A1%B5%E7%A0%81%0A     *%0A     * @return%0A     */%0A    public int getPageNo() %7B%0A        return this.pageable.getPageNo();%0A    %7D%0A%0A
     
@@ -1660,279 +1660,8 @@
  %7D%0A%0A
-    /**%0A     * %E8%8E%B7%E5%8F%96%E6%AF%8F%E9%A1%B5%E5%A4%A7%E5%B0%8F%0A     *%0A     * @return%0A     */%0A    public int getPageSize() %7B%0A        return this.pageable.getPageSize();%0A    %7D%0A%0A    /**%0A     * %E8%8E%B7%E5%8F%96%E8%B5%B7%E5%A7%8B%E5%81%8F%E7%A7%BB%E9%87%8F(%E4%BB%8E0%E5%BC%80%E5%A7%8B)%0A     *%0A     * @return%0A     */%0A    public int getOffset() %7B%0A        return this.pageable.getOffset();%0A    %7D%0A%0A
     

优化PageResult类型,去掉不必填的get方法