• 不连数据库List分页


    package com.jpsycn.kfwggl.common.crawl; import java.util.ArrayList; import java.util.List; public class PageListBean {

        private int currentPage = 1;  //当前页        

    private int rowsCountPerPage = 5;  //每页的数据条数      

       private int totalPage = 0;  //共有多少页    

        private int totalCount = 0; //共有多少行数据   

          private List dataList = null; //待分页的数据  

           private List tempDataList = null;  //每页的数据       

      public PageListBean() {

        }      

       @SuppressWarnings("unchecked")  

    public List getPaper(List dataList/* 待分页的数据 */, int rowsCount/* 每页显示的行数 */)

    {                

    initPageList(dataList, rowsCount);               

      tempDataList = new ArrayList();             

        //currentPage * rowsCountPerPage 定位到当前页的数据数       

      //currentPage * rowsCountPerPage - rowsCountPerPage 定位到当前页的第一条数据       

      for(int i = currentPage * rowsCountPerPage - rowsCountPerPage; i < currentPage * rowsCountPerPage; i++) {        

         if(i >= totalCount) break;                       

      tempDataList.add(dataList.get(i));        

    }               

      return tempDataList;   

      }        

    //待分页的数据,设置记录数,每页记录数,总页数    

    private void initPageList(List dataList, int rowsCount) {             

        this.dataList = dataList;               

      totalCount = dataList.size();        

    rowsCountPerPage = rowsCount;             

        if(totalCount % rowsCountPerPage == 0) {         

        totalPage = totalCount / rowsCountPerPage;       

      } else {            

    totalPage = totalCount / rowsCountPerPage + 1;      

       }   

      }

        public int getCurrentPage() {        

    return currentPage;   

      }

        public void setCurrentPage(int currentPage) {       

      this.currentPage = currentPage;   

      }

        public int getRowsCountPerPage() {      

       return rowsCountPerPage;    

    }

        public void setRowsCountPerPage(int rowsCountPerPage) {      

       this.rowsCountPerPage = rowsCountPerPage;    

    }

        public int getTotalPage() {        

    return totalPage;    

    }

        public void setTotalPage(int totalPage) {    

         this.totalPage = totalPage;    

    }

        public int getTotalCount() {  

           return totalCount;  

       }

        public void setTotalCount(int totalCount) {     

        this.totalCount = totalCount;    

    }

        public List getDataList() {     

        return dataList;    

    }

        public void setDataList(List dataList) {   

          this.dataList = dataList;   

      }

        @SuppressWarnings("unchecked")

     public static void main(String[] args) {                

    List da = new ArrayList();        

    for(int i = 0; i < 25; i++) {            

    da.add(i+1);        

    }                

    PageListBean bean = new PageListBean();        

    List pagerList = bean.getPaper(da, 5);        

    bean.setCurrentPage(bean.getTotalPage());        

    pagerList = bean.getPaper(da, 5);        

    for(int b = 0; b < pagerList.size(); b++) {            

    System.out.println(pagerList.get(b));                    

    }    

    } }

  • 相关阅读:
    Linux使用手册
    Oracle&SQL使用记录
    docker的使用
    springboot与mybatis
    JavaScript与TypeScript总结
    React总结
    React与jsplumb
    DB2入门
    吾尝终日而思矣——2019.02.17
    吾尝终日而思矣——2019.02.12
  • 原文地址:https://www.cnblogs.com/lanblogs/p/3291633.html
Copyright © 2020-2023  润新知