zoukankan      html  css  js  c++  java
  • 分页工具类(JavaBean)

    package com.sec.util;

    import java.io.Serializable;
    import java.util.ArrayList;

    /**
    * 分页JavaBean
    */
    public class PageModel<T> implements Serializable{

    private static final long serialVersionUID = -2487099551056589916L;

    private int pageSize=5; //每页显示的条数
    private int pageNo = 1; //当前页码
    private int totalRecords = 0; //总记录数
    private ArrayList<T> data=null; //当前页的数据

    /**
    * 设置每页显示记录的条数
    */
    public void setPageSize(int size){
    this.pageSize = size;
    }

    /**
    * 获取每页显示的记录的条数
    */
    public int getPageSize(){
    return this.pageSize;
    }

    /**
    * 设置当前页的页码
    */
    public void setPageNo(int no){
    this.pageNo = no;
    }

    /**
    * 获取当前页的页码
    */
    public int getPageNo(){
    return this.pageNo;
    }

    /**
    * 获取总页数
    */
    public int getTotalPages(){
    int temp = (totalRecords+pageSize-1)/pageSize;
    return temp <= 0 ? 1 : temp;
    // if(totalRecords%pageSize==0){
    // return totalRecords/pageSize;
    // }else{
    // return totalRecords/pageSize + 1;
    // }
    }

    /**
    * 设置记录总数
    */
    public void setTotalRecords(int totalRecords){
    this.totalRecords = totalRecords;
    }

    /**
    * 获取记录总数
    */
    public int getTotalRecords(){
    return this.totalRecords;
    }

    /**
    * 设置当前页的数据
    */
    public void setData(ArrayList<T> data){
    this.data = data;
    }

    /**
    * 获取当前页的数据
    */
    public ArrayList<T> getData(){
    return this.data;
    }

    /**
    * 获取首页页码
    */
    public int getIndexPageNo(){
    return 1;
    }

    /**
    * 获取尾页页码
    */
    public int getLastPageNo(){
    return this.getTotalPages();
    }

    /**
    * 获取上一页页码
    */
    public int getPreviousPageNo(){
    if(this.pageNo <= 1){
    return 1;
    }else{
    return this.pageNo-1;
    }
    }

    /**
    * 获取下一页页码
    */
    public int getNextPageNo(){
    if(this.pageNo >= this.getTotalPages()){
    return this.getTotalPages();
    }else{
    return this.pageNo+1;
    }
    }
    }

  • 相关阅读:
    spring-tool-suite-4-4.3.2.RELEASE-e4.12.0-win32.win32.x86_64 下载
    day39_Spring学习笔记_07_CRM_03
    MyEclipse 中 报错 ERROR PARSER:56
    day38_Spring学习笔记_06_CRM_02
    最简单的递归/死循环
    day37_Spring学习笔记_05_CRM_01
    如何在Linux中发现IP地址冲突
    如何在Linux中用命令行工具管理KVM虚拟环境
    使用 Shell 脚本自动化 Linux 系统维护任务
    Linux系统多网卡绑定实战
  • 原文地址:https://www.cnblogs.com/bsyx/p/4129433.html
Copyright © 2011-2022 走看看