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

📄 pagecontroller.java

📁 一个关于物流的管理系统
💻 JAVA
字号:
package com.shunshi.ssh.home.service;
import java.util.Collection;

public class PageController {

  //������
  int totalRowsAmount;
  //ÿҳ����
  int pageSize =20;
  //��ҳ��
  int totalPages;

  //��ǰҳ��
  int currentPage = 1;
  //��һҳ
  int nextPage;
  //��һҳ
  int previousPage;
  //�Ƿ�����һҳ
  boolean hasNext;
  //�Ƿ�����һҳ
  boolean hasPrevious;

  //��ǰҳ��ʼ��
  int pageStartRow;

  //��ǰҳ������
  int pageEndRow;
  private Collection data;

  /**
   * ���캯��
   * @param totalRows ������
   */
  public PageController(int totalRows,int currentPage) {
    setPageController(totalRows,currentPage);
  }

  public PageController(int totalRows,int currentPage,int pageSize){
      this.pageSize = pageSize;
      this.setPageController(totalRows,currentPage);
  }

  public PageController() {
	
}

public void setPageController(int totalRows,int currentPage){

    setTotalRowsAmount(totalRows);
    setCurrentPage(currentPage);
  }

  /**
   * ����������
   * @param i ������
   */
  public void setTotalRowsAmount(int rows) {

    if(rows <0 ){
      totalRowsAmount =  0;
    }else{
      totalRowsAmount = rows;
    }

    if(totalRowsAmount%pageSize==0){
      totalPages = totalRowsAmount / pageSize;
    }else{
      totalPages = totalRowsAmount / pageSize + 1;
    }
  }

  /**
   * ���õ�ǰҳ��
   * @param i
   */
  private void setCurrentPage( int curPage) {

    if(curPage <= 0){
      currentPage = 1;
    }else if(curPage > totalPages){
      currentPage = totalPages;
    }else{
      currentPage = curPage;
    }

    if(currentPage == 1){
      hasPrevious = false;
    }else{
      hasPrevious = true;
    }

    if(currentPage == totalPages){
      hasNext = false;
    }else{
      hasNext = true;
    }


    nextPage = currentPage + 1;
    previousPage = currentPage - 1;

    //���㵱ǰҳ��ʼ�кͽ�����
    if(currentPage != totalPages){

      pageStartRow = (currentPage-1)*pageSize +1;

    }else{
      pageStartRow = (currentPage - 1)*pageSize+1;
    }

    //��¼�����0��ʼ
    pageStartRow -= 1;
    pageEndRow = pageStartRow + pageSize;

  }

  public int getCurrentPage() {
    return currentPage;
  }

  public boolean isHasNext() {
    return hasNext;
  }

  public boolean isHasPrevious() {
    return hasPrevious;
  }

  public int getNextPage() {
    return nextPage;
  }

  public int getPageSize() {
    return pageSize;
  }

  public int getPreviousPage() {
    return previousPage;
  }

  public int getTotalPages() {
    return totalPages;
  }

  public int getTotalRowsAmount() {
    return totalRowsAmount;
  }

  public int getPageStartRow() {
    return pageStartRow;
  }

  public int getPageEndRow(){
      return pageEndRow;
  }

  public String description() {
    String description = "Total:" + this.getTotalRowsAmount() +
        " items " + this.getTotalPages() + " pages,Current page:" +
        this.currentPage + " Previous " + this.hasPrevious +
        " Next:" + this.hasNext +
        " start row:" + this.pageStartRow +
        " end row:" + this.pageEndRow;
    return description;
  }

  public void setData(Collection data) {
    this.data = data;
  }
  public Collection getData() {
    return data;
  }

  public static void main(String args[]){

    Collection c = null;
    PageController pc = new PageController(0,2);
    System.out.println(pc.description());
  }

}



⌨️ 快捷键说明

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