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

📄 pageable.java

📁 java语言编写的程序
💻 JAVA
字号:
/**
 * 
 */
package cn.lab.object;
import java.sql.*;
/**
 * @author Administrator
 *
 */
/**
 * @author Administrator
 *
 */
public class Pageable {
	private int pageSize;
	private int totalRows;
	private int totalPages;
	private static int currentPage;
	private int rowsCount;
	
	public Pageable(ResultSet rs){
		try{
			rs.last();
			}catch (SQLException e){
				e.printStackTrace();
			}
		try{
			this.setTotalRows(rs.getRow());
			}catch(SQLException e1){
				e1.printStackTrace();
			}
		try{
			rs.beforeFirst();
		}catch(SQLException e2){
			e2.printStackTrace();
		}
			
	}
	/**
	 * @return the currentPage
	 */
	public static int getCurrentPage() {
		return currentPage;
	}
	/**
	 * @param currentPage the currentPage to set
	 */
	public   void  setCurrentPage(int page) {
		if(page <=0)
		{
			this.currentPage = 1;
		}
		if(page > this.getTotalPages())
		{
			this.currentPage=this.getTotalPages();
		}
		else
			this.currentPage = page;
		this.setRowsCount((this.currentPage-1)*this.getPageSize()+1);
		System.out.print(this.getRowsCount());		
	}
	
	public int getCurrentPageRowsCount(){
		if(this.getPageSize()==0)
			return this.getTotalRows();
		if(this.getTotalRows()==0)
			return 0;
		if(this.getCurrentPage()!=this.getTotalPages())
			return this.getPageSize();
		return this.getTotalRows()-(this.getTotalPages()-1)+this.getPageSize();
	}
	
	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return this.pageSize;
	}
	/**
	 * @param pageSize the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		if(pageSize>=0)
		{
			this.pageSize=pageSize;
		}else
		{
			this.pageSize=1;
		}
		this.setTotalPages();
	}
	
	public void gotoPage(int page)
	{
		switch(page)
		{
			case-1:
				this.setCurrentPage(1);
			case-2:
				int t = this.getCurrentPage();
				this.setCurrentPage(t - 1);
				break;
			case-3:
				int n = this.getCurrentPage();
				this.setCurrentPage(n + 1);
				break;
			case-4:
				this.setPageSize(this.getTotalPages());
				break;
			default:
				this.setCurrentPage(page);		
		}
	}
	/**
	 * @return the rowsCount
	 */
	public int getRowsCount() {
		return rowsCount;
	}
	/**
	 * @param rowsCount the rowsCount to set
	 */
	public void setRowsCount(int rowsCount) {
		this.rowsCount = rowsCount;
	}
	/**
	 * @return the totalPages
	 */
	public int getTotalPages() {
		return this.totalPages;
	}
	/**
	 * @param totalPages the totalPages to set
	 */
	public void setTotalPages() {
		if(this.getTotalRows()==0)
		{
			this.totalPages=0;
		}else if (this.getPageSize()==0)
		{
			this.totalPages=1;
		}
		else{
			if(this.getTotalRows()%this.getPageSize()!=0)
				this.totalPages=this.getTotalRows()/this.getPageSize()+1;
			else
				this.totalPages=this.getTotalRows()/this.getPageSize();
		}
	}
	/**
	 * @return the totalRows
	 */
	public int getTotalRows() {
		return totalRows;
	}
	/**
	 * @param totalRows the totalRows to set
	 */
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	
	public void pageFirst() throws java.sql.SQLException{
		this.setRowsCount((this.getCurrentPage()-1)*this.getPageSize()+1);
	}
	public void pageLast() throws java.sql.SQLException{
		this.setRowsCount((this.getCurrentPage()-1)*this.getPageSize()
				+this.getCurrentPageRowsCount());
	}


}

⌨️ 快捷键说明

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