zoukankan      html  css  js  c++  java
  • JAVA逻辑分页实现

    
    import org.apache.poi.ss.formula.functions.T;
    import org.springframework.util.CollectionUtils;
    
    import java.util.List;
    
    /**
     * @ClassName PageInfoConvent
     * @Description TODO
     * @Author braless
     * @Date 2021/4/7 18:17
     */
    public class PageInfoConvent<T> {
        private int pageNum;
        private int pageSize;
        private int startRow;
        private int endRow;
        private int pages;
        private List<T> list ;
        public PageInfoConvent(int pageNum,int pageSize,List<T> totalList) {
            this.pageNum = pageNum<=1 ? 1:pageNum;
            this.pageSize = pageSize<=1 ? 1:pageSize;
            if(CollectionUtils.isEmpty(totalList)){
                return ;
            }
            int totalCount = totalList.size();
            if(totalCount<=pageSize){
                this.pages=1;
            }else{
                if(totalCount%pageSize>0){
                    this.pages = totalCount/pageSize+1;
                }else{
                    this.pages = totalCount/pageSize;
                }
            }
            this.startRow = this.pageNum > 0 ? (this.pageNum - 1) * this.pageSize : 0;
            this.endRow = this.startRow + this.pageSize * (this.pageNum > 0 ? 1 : 0);
            if(endRow>totalCount)endRow=totalCount;
            list = totalList.subList(this.startRow,this.endRow);
        }
    //getter /setter 方法
        
    }
    
  • 相关阅读:
    Sentry异常捕获平台
    docker部署RabbitMQ(单机)
    Elasticsearch参数调优
    docker 部署Elasticsearch-权限认证(单节点)
    ElementUI 实现el-table 列宽自适应
    vue 弹幕插件
    linux 命令笔记
    swoole安装笔记
    Swoole学习笔记
    VM安装centos8实战
  • 原文地址:https://www.cnblogs.com/braless/p/14632432.html
Copyright © 2011-2022 走看看