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

📄 pager.java

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻 JAVA
字号:
package com.qrsx.qrsxcrm.web;

/**
 * 分页实体类
 * 
 * @author Administrator
 * 
 */
public class Pager {
	private int totalRows = 0;// 记录总数

	private int totalPages = 0; // 总页数

	private int pageSize = 5;// 每页显示数据条数,默认为条记录5

	private int currentPage = 1; // 当前页数

	private boolean hasPrevious = false; // 是否有上一页

	private boolean hasNext = false; // 是否有下一页

	public Pager() {

	}

	/**
	 * 初始化信息
	 * @param totalRows
	 */
	public void init(int totalRows) {
		refresh(); // 刷新当前页面信息
		this.totalRows = totalRows;
		totalPages = ((totalRows + pageSize) - 1) / pageSize;
		refresh(); // 刷新当前页面信息
	}
	
	public void init(int totalRows, int pageSize) {
		this.totalRows = totalRows;
		this.pageSize = pageSize;
		totalPages = ((totalRows + pageSize) - 1) / pageSize;
		refresh(); // 刷新当前页面信息
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
		refresh();
	}

	
	public int getPageSize() {
		return pageSize;

	}

	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		refresh();
	}

	
	public int getTotalPages() {
		return totalPages;
	}

	
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
		refresh();
	}

	
	public int getTotalRows() {
		return totalRows;
	}

	
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
		refresh();

	}
	public boolean isHasNext() {
		return hasNext;
	}


	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}

	public boolean isHasPrevious() {
		return hasPrevious;
	}

	public void setHasPrevious(boolean hasPrevious) {
		this.hasPrevious = hasPrevious;
	}
	
	// 跳到第一页
	public void first() {
		currentPage = 1;
		this.setHasPrevious(false);
		refresh();
	}

	// 取得上一页(重新设定当前页面即可)
	public void previous() {
		currentPage--;
		refresh();
	}

	// 取得下一页
	public void next() {
		if (currentPage < totalPages) {
			currentPage++;
		}
		refresh();
	}
	// 跳到最后一页
	public void last() {
		currentPage = totalPages;
		this.setHasNext(false);
		refresh();
	}
	
	/**
	 * 根据页面传递的参数值进行页面操作
	 * @param action
	 */
	public void doAction(String action) {

		if (action != null) {
			// 根据传递进来的参数控制页面的前进后退
			if (action.equalsIgnoreCase("previous")) {
				this.previous();
			} else if (action.equalsIgnoreCase("next")) {
				this.next();
			} else if (action.equalsIgnoreCase("first")) {
				this.first();
			} else if (action.equalsIgnoreCase("last")) {
				this.last();
			} else {
				this.setCurrentPage(Integer.parseInt(action));
			}
		}
	}

	// 刷新当前页面信息   根据当前的页码判断是否有下  or 上一页

	public void refresh() {

		if (totalPages <= 1) {

			hasPrevious = false;

			hasNext = false;

		} else if (currentPage == 1) {

			hasPrevious = false;

			hasNext = true;

		} else if (currentPage == totalPages) {

			hasPrevious = true;

			hasNext = false;

		} else {
			hasPrevious = true;
			hasNext = true;

		}

	}

}

⌨️ 快捷键说明

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