• 分页实体


    1.通过该实体,只需传入当前页就能获得起始记录数,默认每页10条 ,传入总记录数,就能得到总页数

    package com.****.util.mybatis;
    
    import java.io.Serializable;
    
    public final class Pager implements Serializable {
    
        /**
         * 默认的序列化版本 id.
         */
        private static final long serialVersionUID = 1L;
        /**
         * 分页查询开始记录位置.
         */
        private int begin=0;
        /**
         * 分页查看下结束位置.
         */
        private int end=10;
        /**
         * 每页显示记录数.
         */
        private int rows = 10;
        /**
         * 查询结果总记录数.
         */
        private int totalRecords;
        /**
         * 当前页码.
         */
        private int page=1;
        /**
         * 总共页数.
         */
        private int pageCount=0;
        
        private String sort; //排序的列
        private String order; //顺序或倒序
    
        public Pager() {
            this.begin=0;
            this.end=10;
        }
    
        /**
         * 构造函数.
         * 
         * @param begin 起始位置
         * @param length 每页显示记录数
         */
        public Pager(int begin, int length) {
            this.begin = begin;
            this.rows = length;
            this.end = this.begin + this.rows;
            this.page = (int) Math.floor((this.begin * 1.0d) / this.rows) + 1;
        }
    
        /**
         * @param begin 起始位置
         * @param length 每页显示记录数
         * @param totalRecords 查询结果总记录数.
         */
        public Pager(int begin, int length, int totalRecords) {
            this(begin, length);
            this.totalRecords = totalRecords;
        }
    
        /**
         * 设置页数,自动计算数据范围.
         * @param pageNo
         */
        public Pager(int pageNo) {
            this.page = pageNo;
            pageNo = pageNo > 0 ? pageNo : 1;
            this.begin = this.rows * (pageNo - 1);
            this.end = this.rows * pageNo;
        }
    
        /**
         * @return the begin
         */
        public int getBegin() {
            return begin;
        }
    
        /**
         * @return the end
         */
        public int getEnd() {
            return end;
        }
    
        /**
         * @return the length
         */
        public int getRows() {
            return rows;
        }
    
        /**
         * @param length
         * the length to set
         */
        public void setRows(int rows) {
            this.rows = rows;
            this.begin = this.rows * (page - 1);
            this.end = this.rows * page;
        }
    
        public void setBegin(int begin) {
            this.begin = begin;
        }
    
        public void setEnd(int end) {
            this.end = end;
        }
    
        /**
         * @return the totalRecords
         */
        public int getTotalRecords() {
            return totalRecords;
        }
    
        /**
         * @param totalRecords
         * 传入总记录数得到就能得到页数
         */
        public void setTotalRecords(int totalRecords) {
            this.totalRecords = totalRecords;
            this.pageCount = (int) Math.floor((this.totalRecords * 1.0d)
                    / this.rows);
            if (this.totalRecords % this.rows != 0) {
                this.pageCount++;
            }
        }
    
        /**
         * @return the pageNo
         */
        public int getPage() {
            return page;
        }
    
        /**
         * @param pageNo the page to set
         * 传到当前页就能得到开始记录数
         */
        public void setPage(int page) {
            this.page = page;
            page = page > 0 ? page : 1;
            this.begin = this.rows * (page - 1);
            this.end = this.rows * page;
        }
    
        /**
         * @return the pageCount
         */
        public int getPageCount() {
            if (pageCount == 0) {
                return 1;
            }
            return pageCount;
        }
    
        /**
         * @param pageCount
         * the pageCount to set
         */
        public void setPageCount(int pageCount) {
            this.pageCount = pageCount;
        }
        
        public String getSort() {
            return sort;
        }
    
        public void setSort(String sort) {
            this.sort = sort;
        }
    
        public String getOrder() {
            return order;
        }
    
        public void setOrder(String order) {
            this.order = order;
        }
    
        @Override
        public String toString() {
            final StringBuilder builder = new StringBuilder("begin=").append(begin)
                    .append(", end=").append(end).append(", length=")
                    .append(rows).append(", totalRecords=").append(totalRecords)
                    .append(", pageNo=").append(page).append(", pageCount=")
                    .append(pageCount);
            return builder.toString();
        }
        
    }
  • 相关阅读:
    Mac上的常用软件
    Mac上在iterm2中使用ls时,出现Operation not permitted
    Typora常用操作
    Mac上的qemusystemaarch64占用太多内存
    软件质量管理总结
    postgres使用记录
    Linux 包含中文字符的文件名无法使用shell 选中或复制
    常见硬件知识
    iterm2 常用操作
    C# 通过 HTTPModule 防范 DOS
  • 原文地址:https://www.cnblogs.com/-scl/p/7813585.html
Copyright © 2020-2023  润新知