⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagecontroller.java

📁 上一上传oa系统漏掉web-inf文件夹
💻 JAVA
字号:
package com.oa.page;

import java.util.*;

public class PageController implements IPageModel {
  private Collection model;

  //数据总行数 
  private int totalRowCount = 0; 

  //总页数
  private int pageCount = 0;

  //每页应显示的行数
  private int maxPageRowCount = 0;

  //当前页行数
  private int currPageRowCount = 0;

  //当前页号
  private int currPageNum;

  //默认构造 
  public PageController() {
    super();
  }

  //传入模型
  public PageController(Collection model) {
    setPageController(model);
  }

  //设一个分页模型
  public void setPageController(Collection model) {
    this.model = model;
    this.totalRowCount = model.size();
  }
  /**
   * 总页数
   * @return int
   */
  public int getPageCount() {
    return this.pageCount;
  }

  /**
   * getPageContents
   *
   * @param intPageNum int
   * @return Object
   */
  public Object getPageContents(int intPageNum) {
    //非法数据处理
    if(intPageNum<1){
      intPageNum=1;
    }
    if(intPageNum>pageCount){
      intPageNum=pageCount;
    }
    //指定当前页
    this.currPageNum=intPageNum;
    int i = 0;
    ArrayList arr = new ArrayList();
    //如果是合法的范围
    if (intPageNum > 0 && intPageNum <= pageCount) {
      //计算该页的开始号和结束号
      int lfromrow = (intPageNum - 1) * maxPageRowCount;
      arr = (ArrayList) getElementsAt(model, lfromrow, lfromrow + maxPageRowCount-1);
    }
    currPageNum=intPageNum;
    return arr;
  }

  public Object getLastPage() {
    return this.getPageContents(pageCount);
  }

  public Object getFirstPage() {
    return this.getPageContents(0);
  }

  /**
   * getCurrentPageRowsCount
   *
   * @return int
   */
  public int getCurrentPageRowsCount() {
    if(currPageNum<pageCount){
      return maxPageRowCount;
    }
    else{//最后一页
      return totalRowCount-(pageCount-1)*maxPageRowCount;
    }
  }
  public int getCurrentPageNum(){
    return currPageNum;
  }
  /**
   * setMaxPageRows
   *
   * @return int
   */
  public void setMaxPageRows(int rowCount) {
    maxPageRowCount = rowCount;
    //计算总页数
    if (totalRowCount % maxPageRowCount > 0) { //有余数
      pageCount = totalRowCount / maxPageRowCount + 1;
    }
    else {
      pageCount = totalRowCount / maxPageRowCount;
    }
  }

  /**
   * getMaxPageRows
   */
  public int getMaxPageRows() {
    return maxPageRowCount;
  }
  //私有方法,返回集合中指定范围的数据
  private Object getElementsAt(Collection model, int fromIndex, int toIndex) {
    Iterator iter = model.iterator();
    ArrayList arr = new ArrayList();
    if (iter != null) {
      int i = 0;
      while (iter.hasNext()) {
        Object obj=iter.next();
        if (i >= fromIndex && i <= toIndex) {
          arr.add(obj);
        }
        if (i > toIndex) {
          break;
        }
         i = i + 1;
      }
    }
    return arr;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -