Java当中的分页显示公共类
来源:互联网 发布:手机位置模拟软件 编辑:程序博客网 时间:2024/06/08 13:22
package com.guoqj.common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
/**
*
* @author guoqj
* 分页公共类
*
*/
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);
}
/**
* 获取当前页
* @return int
*/
public int getCurPage() {
return curPage;
}
/**
* 获取总页数
* @return int
*/
public int getPageCount() {
return pageCount;
}
public int getPageSize() {
return pageSize;
}
public int getRowsCount() {
return rowsCount;
}
public int first(){
return 1;
}
public int last(){
return this.rowsCount;
}
/**
* 上一页
* @return int
*/
public int previous() {
return (curPage - 1 < 1) ? 1 : curPage-1;}
/**
* 下一页
* @return int
f*/
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 += "首页 上一页 ";
}else{
str+="<a href='"+fileName+temp+"cur_page=1'>首页</a> ";
str+="<a href='"+fileName+temp+"cur_page="+(curPage-1)+"'>上一页</a> ";
}
if(isLast()){
str+="下一页 尾页 ";
}else{
str+="<a href='"+fileName+temp+"cur_page="+(curPage+1)+"'>下一页</a> ";
str+="<a href='"+fileName+temp+"cur_page="+pageCount+"'>尾页</a> ";
}
str+=" 共<b>"+rowsCount+"</b>条记录 ";
str+=" 转到<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;
}
}
- Java当中的分页显示公共类
- java的分页显示
- Java当中的String类
- 【Java公共类】分页Page开发
- 分页显示数据的java工具类
- java在eclipse当中关于图片显示的处理
- 分页的公共代码
- 公共的分页方法
- 关于Java当中的RunTime类
- java 当中的集合
- Java当中的线程
- Java当中的数组
- java当中的executor
- Java当中的数组
- java当中的日历
- pagedata公共类 分页
- Java当中的IO(三)
- Java当中的线程(三)
- 单源点最短路径Dijkstra算法的JAVA实现
- [随便想想] 透明度:告诉美国人,中国没有国家战略
- [随便想想] 新版龟兔赛跑的故事
- 页码设置,随心所欲—Word非连续页码设置技巧
- pku 1088 滑雪
- Java当中的分页显示公共类
- 我的烦恼
- 今天终于下定决心,好好学习技术
- c++ asio: line-based echo server
- JavaScript如何操作cookie?
- 从不看编程书的Flex牛人
- 常用正则表达式总结
- JavaScript获取GridView选择的行内容
- Java游戏开发中怎样才能获得更快的FPS?