zoukankan      html  css  js  c++  java
  • list分页,集合分页

    package com.sensor.sellCabinet.util;
    
    import lombok.Data;
    
    import java.util.Collections;
    import java.util.List;
    
    @Data
    public class Paging {
    
        private Integer total;//总条数
        private Integer totalPage;//总页数
        private Integer size;//每页条数
        private Integer current;//当前页码
        private Integer queryIndex;//当前页从第几条开始查
    
        public static Paging pagination(Integer total,Integer current,Integer pageSize){
            if(current==null || current<=0){
                current=1;
            }
            if(pageSize==null || pageSize<=0){
                pageSize=10;
            }
            Paging page = new Paging();
            page.setTotal(total);
            Integer totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
            page.setTotalPage(totalPage);
            page.setCurrent(current);
            page.setSize(pageSize);
            page.setQueryIndex(pageSize * (current-1));
            return page;
        }
    
        public  <T> List<T> subListt(List<T> t){
            int fromIndex = queryIndex;
            int toIndex = 0;
            if (fromIndex + getSize() >= total){
                toIndex = total;
            }else {
                toIndex = fromIndex + getSize();
            }
            if (fromIndex > toIndex){
                return Collections.EMPTY_LIST;
            }else{
                return t.subList(fromIndex,toIndex);
            }
        }
    }

    调用案例

                Paging paging = Paging.pagination(normal.size(),current,size);
                data.put("normal",paging.subListt(normal));
  • 相关阅读:
    B-树和B+树
    线程与内核对象的同步-2
    线程与内核对象的同步
    高级线程同步 临界区
    Levenshtein Distance (编辑距离) 算法详解
    平衡二叉树
    静态查找表
    C++中的容器类详解
    How do I list all tables/indices contained in an SQLite database
    SmartGit STUDY 2
  • 原文地址:https://www.cnblogs.com/qq376324789/p/15304826.html
Copyright © 2011-2022 走看看