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

📄 pagelist.java

📁 J2EE eclipse 下开发数据库一个插件
💻 JAVA
字号:
package com.tanghan.util;

/**
 * 本类是一个参数类。<br>
 * 主要在作分页显示时使用。其表示从什么地方开始取数据,取多少条数据。<br>
 * 在该参数中还可以可到合乎条件的数据的总数量。<br>
 * <br>
 * 使用说明:<br>
 * PageList主要是记录在一个列表中没次需要列出多少条记录,以及相关的信息<br>
 * 其记录的信息包括<br>
 * <li>showAll 是否显示所有数据,如果不需要程序分页,则showAll =  true</li>
 * <li>start (只读)起始位置,根据currentPage,list得到, 其主要指明,从第几条数据开始取数和显示,如果start=11,那么程序就应该从满足条件的第11条数据开始显示</li>
 * <li>list 每次显示的数据数目 如果start=11,而list=10,那么程序就应该显示从11到20的满足条件的10条数据</li>
 * <li>size 总的记录条数</li>
 * <li>currentPage 当前页数 至少为1</li>
 * <li>totalPage (只读)总的记录条数, 根据list和size得到,当无法计算时,为1</li>
 * 
 * @author Jerry Tang
 * @version v0.1.0
 * @createdate 2003-3-25
 * @copyright  (C) 2003 Tanghan工作组
 * 
 *
 */
public class PageList {

	/** 是否显示所有数据,
	 * 是则不用分页显示
	 * 否则分页显示
	 * */
	protected boolean showAll;
	
	/** (只读)起始位置,根据currentPage,list得到, 
	 * 其主要指明,从第几条数据开始取数和显示,如果start=11,那么程序就应该从满足条件的第11条数据开始显示
	 * 
	 * */
	protected long start;
	/** 每次显示的数据数目 
	 * 如果start=11,而list=10,那么程序就应该显示从11到20的满足条件的10条数据
	 * */
	protected int list;
	
	/**总的记录条数
	 * 该属性比较特殊,其在查询结果出来以后得到所有记录的条数,然后改变该属性
	 * */
	protected long size;
	/**
	 * 当前页数 至少为1
	 * */
	protected long currentPage;

	/**
	 * (只读)总的记录条数
	 * 根据list和size得到,当无法计算时,为1
	 * */
	protected long totalPage;
	
	/**构造函数
	 * */
	public PageList(){
		init();
	}	
	/**构造函数
	 * @param showAll 是否显示所有数据
	 * */
	public PageList(boolean showAll){
		init();
		this.showAll = showAll;
	}	
	
	/**构造函数
	 * @param currentPage 当前页面
	 * @param list 每一页的记录条数
	 * */	
	public PageList(long currentPage,int list){
		init();
		if(currentPage<1){
			this.currentPage=1;
		}else{
			this.currentPage = currentPage;
		}
		
		if(list<1){
			this.list=1;
		}else{
			this.list = list;
		}
		changeStart();
		
	}
	/**数据初始化*/
	protected void init(){
		showAll = false;
		list = 20;
		size = 0;
		currentPage = 1;
		totalPage = 1;
		changeStart();
		changTotalPage();
	}
	
	/**
	 * 根据currentPage和list修改start的值
	 * */
	protected void changeStart(){
		start = (currentPage>1)? (currentPage-1) * list +1 : 1;
	}
	
	/**
	 * Returns the list.
	 * @return int
	 */
	public int getList() {
		return list;
	}

	/**
	 * Returns the showAll.
	 * @return boolean
	 */
	public boolean isShowAll() {
		return showAll;
	}

	/**
	 * Returns the size.
	 * @return long
	 */
	public long getSize() {
		return size;
	}

	/**
	 * Returns the start.
	 * @return long
	 */
	public long getStart() {
		return start;
	}

	/**
	 * Returns the totalPage.
	 * @return long
	 */
	public long getTotalPage() {
		return totalPage;
	}

	/**
	 * Sets the list.
	 * @param list The list to set
	 */
	public void setList(int list) {
		this.list = list;
		changeStart();
		changTotalPage();
	}

	/**
	 * Sets the showAll.
	 * @param showAll The showAll to set
	 */
	public void setShowAll(boolean showAll) {
		this.showAll = showAll;
	}

	/**
	 * Sets the size.
	 * @param size The size to set
	 */
	public void setSize(long size) {
		this.size = size;
		changTotalPage();
	}
	/**修改总共多少页*/
	private void changTotalPage(){
		if(size>0){
			totalPage = ((size%list)>0)? size/list+1: size/list;
		}else{
			totalPage = 1;
		}
		currentPage = (currentPage>totalPage)?totalPage:currentPage;

	}


	/**
	 * Returns the currentPage.
	 * @return long
	 */
	public long getCurrentPage() {
		return currentPage;
	}

	/**
	 * Sets the currentPage.
	 * @param currentPage The currentPage to set
	 */
	public void setCurrentPage(long currentPage) {
		this.currentPage = currentPage;
		changeStart();
	}
	/**
	 * 重新初始化
	 * */
	public void reset(){
		init();
	}

}

⌨️ 快捷键说明

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