• 不连数据库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));                    

    }    

    } }

  • 相关阅读:
    Ignatius and the Princess IV
    JavaFX+SpringBoot+验证码功能的小型薪酬管理系统
    JFX11+Maven+IDEA 发布跨平台应用的完美解决方案
    一个开源的跨平台音乐播放与音乐下载器
    JavaFX获取屏幕尺寸
    OkHttp:NoClassDefFoundError
    jasypt-spring-boot提示Failed to bind properties
    JFX11+IDEA跨平台打包发布的完美解决办法
    IDEA通过Maven打包JavaFX工程(OpenJFX11)
    IDEA 配置文件位置
  • 原文地址:https://www.cnblogs.com/lanblogs/p/3291633.html
Copyright © 2020-2023  润新知