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

📄 pagebean.java

📁 --------------------java实现的BBS论坛系统
💻 JAVA
字号:
package dao;

import java.sql.Connection;
import java.util.*;

public class PageBean {
	private ArrayList list;
	private int num;//总信息数
	private int ye;//每页信息数
	private int start;//每页开始下标
	private int end;//每页结束下标
	private int yeshu;//总页数
	private ConDB db;
	private String where = "";
	private boolean bool;

	public boolean isBool() {
		return bool;
	}

	public void setBool(boolean bool) {
		this.bool = bool;
	}

	private PageBean(){}
	
	public PageBean (int ye,String where) {
		db = new ConDB();
		this.where = where;
		num = db.getRecordCount("select count( * ) from bdetail " + where);
		start = 0;
		this.ye = ye;
		end = (ye > num)? num : ye;
		yeshu = (num % ye == 0) ? num / ye : num / ye + 1;
		db.close();
	}
	public int getNum() {
		return num;
	}
	
	public int getYe() {
		return ye;
	}
	//首页
	public List shouYe() {
		start = 0;
		end = (ye > num)? num : ye;
		return this.xunHuan();
	}
	//上一页
	public List shangYiYe() {	
		if(start - ye <= 0) {
			return shouYe();
		}
		
		end = start;
		start -= ye;

		return this.xunHuan();
	}
	//下一页
	public List xiaYiYe() {	
		if(num - end <= ye) {
			return weiYe();
		}
		
		start = end;
		end += ye;
		
		return this.xunHuan();
	}
	//最后一页
	public List weiYe() {
		
		if(num % ye == 0) {
			start = num - ye;
		}
		else {
			start = num - num % ye;
		}
		end = num;	
		
		return this.xunHuan();
	}
	//页定位
	public List dingWei(int n) {
		if(n > yeshu || n <= 0) {
			throw new Num_Ye();
		}	
		if(n == 1) {
			return this.shouYe();
		}
		if(n == yeshu) {
			return this.weiYe();
		}
		end = n * ye;
		start = end - ye;
		
		return this.xunHuan();
	}
	
	public int getYeShu() {
		return yeshu;
	}
	
	public int getEnd() {
		return end;
	}
	
	public int getStart() {
		return start;
	}
	
	private List xunHuan() {
		String sql = "select * from bdetail " + where + " limit " + start + "," + ( end - start );
		db = new ConDB();
		
		List list = db.listData( sql );
		
		db.close();
		return list;
	}
	
	class Num_Ye extends RuntimeException {
		Num_Ye() {
			super("您输入的页数与总页数不匹配 *_*b");
		}
	}
	
	class Num_num extends RuntimeException {
		Num_num() {
			super("您的参数YE不合法,为零或者大于总信息数 *_*b");
		}
	}

}

⌨️ 快捷键说明

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