分页Page对象

2021-12-07 19:56:32 浏览数 (1)

发表于2016-05-262019-01-01 作者 wind

代码语言:javascript复制
/**
 * 分页对象,包含页码,每页条数,总条数 User: yangyan Date: 13-11-18 Time: 下午8:59 To change this
 * template use File | Settings | File Templates.
 */
public class Page implements Serializable {

    private static final long serialVersionUID = -784438755770041677L;
    private int page = 1;
    private int pageSize = 50;
    private long total = 0;

    public int getOffset() {
        return (page - 1) * pageSize;
    }

    public int getStart() {
        return getOffset();
    }

    public int getLimit() {
        return getPageSize();
    }

    public int getTotalPage() {
        return (int) ((total   pageSize) / pageSize);
    }

    public Page() {
    }

    public Page(int page, int pageSize) {
        this.page = page;
        this.pageSize = pageSize;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

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

    public long getTotal() {
        return total;
    }

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

    /**
     * 另一种形式
     */
    public static class Offset extends Page {

        private static final long serialVersionUID = -4518025561523700841L;
        private int start = 0;
        private int limit = 50;

        public Offset() {
        }

        public Offset(int start, int limit) {
            super(1, limit);
            this.start = start;
            this.limit = limit;
            if (start < limit) {
                setPage(1);
            } else {
                setPage((start   limit * 2 - 1) / limit);
            }

        }

        public int getLimit() {
            return limit;
        }

        public int getStart() {
            return start;
        }

        public void setLimit(int limit) {
            this.limit = limit;
            if (start < limit) {
                setPage(1);
            } else {
                setPage((start   limit * 2 - 1) / limit);
            }
        }

        public void setStart(int start) {
            this.start = start;
            if (start < limit) {
                setPage(1);
            } else {
                setPage((start   limit * 2 - 1) / limit);
            }
        }

    }

    @Override
    public String toString() {
        return "(page:"   this.getPage()   " pageSize:"   this.getPageSize()   ")";
    }
}

0 人点赞