zoukankan      html  css  js  c++  java
  • org.springside.modules.orm中的page类自我解读

    //
    // Source code recreated from a .class file by IntelliJ IDEA
    // (powered by Fernflower decompiler)
    //
    import java.util.Collections;
    import java.util.List;
    import org.apache.commons.lang.StringUtils;
    
    public class Page<T> {
    
        /*静态变量,用于设置结果是按照正序排列还是反序排列*/
        public static final String ASC = "asc";
        public static final String DESC = "desc";
    
        /*当前页码*/
        protected int pageNo = 1;
         /*页面容量*/
        protected int pageSize = 1;
        /*orderBy表示通过那个进行排序,比如说:id*/
        protected String orderBy = null;
        /*order是设置以哪种方式进行排序:可以使ASC也可以是DESC*/
        protected String order = null;
        /*只是是否自动计算*/
        protected boolean autoCount = true;
    
        /*以下2个参数常作为 分页所需的"返回结果"! */
        //result表示当页面存在的实体类集合。
        protected List<T> result = Collections.emptyList();
        //totalCount表示当前页面总条数。
        protected long totalCount = -1L;
    
        public Page() {
        }
    
        public Page(int pageSize) {
            this.setPageSize(pageSize);
        }
    
        public Page(int pageSize, boolean autoCount) {
            this.setPageSize(pageSize);
            this.setAutoCount(autoCount);
        }
    
        public int getPageNo() {
            return this.pageNo;
        }
    
        public void setPageNo(int pageNo) {
            this.pageNo = pageNo;
            if(pageNo < 1) {
                this.pageNo = 1;
            }
    
        }
    
        public int getPageSize() {
            return this.pageSize;
        }
    
        public void setPageSize(int pageSize) {
            this.pageSize = pageSize;
            if(pageSize < 0) {
                this.pageSize = 1;
            }
    
        }
    
        /**
         * 获得当前页面第一条数据的排列
         * @return
         */
        public int getFirst() {
            return (this.pageNo - 1) * this.pageSize + 1;
        }
    
        public String getOrderBy() {
            return this.orderBy;
        }
    
        public void setOrderBy(String orderBy) {
            this.orderBy = orderBy;
        }
    
        public boolean isOrderBySetted() {
            return StringUtils.isNotBlank(this.orderBy) && StringUtils.isNotBlank(this.order);
        }
    
        public String getOrder() {
            return this.order;
        }
    
        public void setOrder(String order) {
            String[] orders = StringUtils.split(StringUtils.lowerCase(order), ',');
            String[] var6 = orders;
            int var5 = orders.length;
    
            for(int var4 = 0; var4 < var5; ++var4) {
                String orderStr = var6[var4];
                if(!StringUtils.equals("desc", orderStr) && !StringUtils.equals("asc", orderStr)) {
                    throw new IllegalArgumentException("排序方向" + orderStr + "不是合法值");
                }
            }
    
            this.order = StringUtils.lowerCase(order);
        }
    
        public boolean isAutoCount() {
            return this.autoCount;
        }
    
        public void setAutoCount(boolean autoCount) {
            this.autoCount = autoCount;
        }
    
        public List<T> getResult() {
            return this.result;
        }
    
        public void setResult(List<T> result) {
            this.result = result;
        }
    
        public long getTotalCount() {
            return this.totalCount;
        }
    
        public void setTotalCount(long totalCount) {
            this.totalCount = totalCount;
        }
    
        /**
         * 获取一共有多少页(设置的是总条数)
         * @return
         */
        public long getTotalPages() {
            if(this.totalCount < 0L) {
                return -1L;
            } else {
                long count = this.totalCount / (long)this.pageSize;
                if(this.totalCount % (long)this.pageSize > 0L) {
                    ++count;
                }
    
                return count;
            }
        }
    
        /**
         * 是否还有下一页
         * @return
         */
        public boolean isHasNext() {
            return (long)(this.pageNo + 1) <= this.getTotalPages();
        }
    
        /**
         * 得到下一页的页码
         * @return
         */
        public int getNextPage() {
            return this.isHasNext()?this.pageNo + 1:this.pageNo;
        }
    
        /**
         * 是否有上一页
         * @return
         */
        public boolean isHasPre() {
            return this.pageNo - 1 >= 1;
        }
    
        /**
         * 得到上一页页码
         * @return
         */
        public int getPrePage() {
            return this.isHasPre()?this.pageNo - 1:this.pageNo;
        }
    }
     

     对于上述代码需要有几点强调的:

    1.Page类本质来讲仅仅是一个辅助类,其中包含的是一些争对分页的辅助数据,具体怎么用,还是需要自己进行处理的。

    2.XXX随时补充。。。

  • 相关阅读:
    UVA 133 The Dole Queue
    HDOJ(HDU) 2103 Family planning(需要注意范围)
    HDOJ(HDU) 2097 Sky数(进制)
    HDOJ(HDU) 2093 考试排名(Arrays.sort排序、类的应用)
    HDOJ(HDU) 2091 空心三角形
    HDOJ(HDU) 2090 算菜价(简单水题、)
    HDOJ(HDU) 2088 Box of Bricks(平均值)
    HDOJ(HDU) 2083 简易版之最短距离(中位数)
    Java---常用基础面试知识点
    Java---练习(面试题) :字符串截取(2-最终版)
  • 原文地址:https://www.cnblogs.com/LiuChunfu/p/4986199.html
Copyright © 2011-2022 走看看