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

📄 pageresultset.java

📁 学生学籍管理系统sql 学生学籍管理系统sql
💻 JAVA
字号:
package com.record.publicCode;

import java.util.*; 

public class PageResultSet {
	private Collection data = null;
	private int curPage;
	private int pageSize;
	private int rowsCount;
	private int pageCount; 

	public PageResultSet(Collection data) {
		this.data = data;
		this.curPage = 1;
		this.pageSize = 10;
		this.rowsCount = data.size();
		this.pageCount = (int) Math.ceil((double) rowsCount/pageSize);
	} 

	public PageResultSet(Collection data, int curPage) {
		this.data = data;
		this.curPage = curPage;
		this.pageSize = 10;
		this.rowsCount = data.size();
		this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
		} 

	public PageResultSet(Collection data, int curPage, int pageSize) {
		this.data = data;
		this.curPage = curPage;
		this.pageSize = pageSize;
		this.rowsCount = data.size();
		this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
		} 

	public int getCurPage() {
		return curPage;
		} 

	public int getPageSize() {
		return pageSize;
		} 

	public int getRowsCount() {
		return rowsCount;
		} 

	public int getPageCount() {
		return pageCount;
		}
	public int first() {
		return 1;
		}
	public int last() {
		return pageCount;
		}
	public int previous() {
		return (curPage - 1 < 1) ? 1 : curPage - 1;
		}
	public int next() {
		return (curPage + 1 > pageCount) ? pageCount : curPage + 1;
		} 

	public boolean isFirst() {
		return (curPage==1)?true:false;
		} 

	public boolean isLast() {
		return (curPage==pageCount)?true:false;
		}
	public Collection getData() {
		Collection curData = null;
		if (data != null) {
			int start = (curPage - 1) * pageSize;
			int end = 0;
			if (start + pageSize > rowsCount)
				end = rowsCount;
			else
				end = start + pageSize;
			ArrayList arrayCurData = new ArrayList();
			ArrayList arrayData = null;
			Vector vectorCurData = new Vector();
			Vector vectorData = null;
			boolean isArray = true;
			if (data instanceof ArrayList) {
				arrayData = (ArrayList) data;
				isArray = true;
			} else if (data instanceof Vector) {
				vectorData = (Vector) data;
				isArray = false;
			}
			for (int i = start; i < end; i++) {
				if (isArray) {
					arrayCurData.add(arrayData.get(i));
				} else {
					vectorData.add(vectorData.elementAt(i));
				}
			}
			if (isArray) {
				curData = (Collection) arrayCurData;
			} else {
				curData = (Collection) vectorCurData;
			}
		}
		return curData;
		}
	public String getToolBar(String fileName){
		String temp="";
		if(fileName.indexOf("?")==-1)
		{
			temp="?";
		}
		else
		{
			temp="&";
		}
		String str="<form method='post' name='frmPage' action='"+fileName+"'>";
		str+="<p align='center'>";
		if(isFirst())
			str+="首页 上一页&nbsp;";
		else
		{
			str+="<a href='"+fileName+temp+"cur_page=1'>首页</a>&nbsp;";
			str+="<a href='"+fileName+temp+"cur_page="+(curPage-1)+"'>上一页</a>&nbsp;";
		}
		if(isLast())
			str+="下一页 尾页&nbsp;";
		else
		{
			str+="<a href='"+fileName+temp+"cur_page="+(curPage+1)+"'>下一页</a>&nbsp;";
			str+="<a href='"+fileName+temp+"cur_page="+pageCount+"'>尾页</a>&nbsp;";
		}
		str+="&nbsp;共<b>"+rowsCount+"</b>条记录&nbsp;";
		str+="&nbsp;转到<select name='page' onChange=\"location='"+fileName+temp+"cur_page='+this.options[this.selectedIndex].value\">";
		for(int i=1;i<=pageCount;i++)
		{
			if(i==curPage)
				str+="<option value='"+i+"' selected>第"+i+"页</option>";
			else
				str+="<option value='"+i+"'>第"+i+"页</option>";
		}
		str+="</select></p></form>";
		return str;
		}
} 

⌨️ 快捷键说明

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