package com.sict.employeeManagement.help;
import java.util.ArrayList;
import java.util.Iterator;
import com.sict.employeeManagement.data.SzEmployee;
public class PageBean {
int currentPage=1; //当前页
public int totalPages=0; //总页数
int pageRecorders=10;//每页5条数据
int totalRows=0; //总数据数
int pageStartRow=0;//每页的起始数
int pageEndRow=0; //每页显示数据的终止数
boolean hasNextPage=false; //是否有下一页
boolean hasPreviousPage=false; //是否有前一页
ArrayList arrayList;
Iterator it;
public PageBean(){}
public PageBean(ArrayList arrayList){
this.arrayList=arrayList;
totalRows=arrayList.size();
// System.out.print(totalRows);
it=arrayList.iterator();
hasPreviousPage=false;
currentPage=1;
if((totalRows%pageRecorders)==0)
{
totalPages=totalRows/pageRecorders;
}
else
{
totalPages=totalRows/pageRecorders+1;
}
if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if(totalRows<pageRecorders)
{
this.pageStartRow=0;
this.pageEndRow=totalRows;
}
else
{
this.pageStartRow=0;
this.pageEndRow=pageRecorders;
}
}
/**
* @return Returns the currentPage.
*/
public String getCurrentPage() {
return this.toString(currentPage);
}
/**
* @param currentPage The currentPage to set.
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
/**
* @return Returns the pageRecorders.
*/
public int getPageRecorders() {
return pageRecorders;
}
/**
* @param pageRecorders The pageRecorders to set.
*/
public void setPageRecorders(int pageRecorders) {
this.pageRecorders = pageRecorders;
}
/**
* @return Returns the pageEndRow.
*/
public int getPageEndRow() {
return pageEndRow;
}
/**
* @return Returns the pageStartRow.
*/
public int getPageStartRow() {
return pageStartRow;
}
/**
* @return Returns the totalPages.
*/
public String getTotalPages() {
return this.toString(totalPages);
}
/**
* @return Returns the totalRows.
*/
public String getTotalRows() {
return this.toString(totalRows);
}
/**
* @return Returns the hasNextPage.
*/
public boolean isHasNextPage() {
return hasNextPage;
}
/**
* @param hasNextPage The hasNextPage to set.
*/
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
/**
* @return Returns the hasPreviousPage.
*/
public boolean isHasPreviousPage() {
return hasPreviousPage;
}
/**
* @param hasPreviousPage The hasPreviousPage to set.
*/
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public SzEmployee[] getNextPage(){
currentPage=currentPage+1;
// System.out.println("PageBean.getNextPage()正在执行;");
// System.out.println("参数currentPage="+currentPage);
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
// System.out.println("参数hasNextPage="+hasNextPage);
// System.out.println("准备执行PageBean.getBooks()");
SzEmployee[] employees=getSzEmployees();
this.description();
return employees;
}
public SzEmployee[] getPreviouspage(){
currentPage=currentPage-1;
if(currentPage==0){currentPage=1;}
if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
SzEmployee[] employees=getSzEmployees();
this.description();
return employees;
}
public SzEmployee[] getFirstpage(){
currentPage=1;
if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
SzEmployee[] employees=getSzEmployees();
this.description();
return employees;
}
public SzEmployee[] getLastpage(){
currentPage=totalPages;
if(currentPage>=totalPages)
{
hasNextPage=false;
}
else
{
hasNextPage=true;
}
if((currentPage-1)>0)
{
hasPreviousPage=true;
}
else
{
hasPreviousPage=false;
}
SzEmployee[] employees=getSzEmployees();
this.description();
return employees;
}
public SzEmployee[] getSzEmployees(){
// System.out.println("pageBean.getPros()开始执行;");
if(currentPage*pageRecorders<totalRows){//判断是否为最后一页
pageEndRow=currentPage*pageRecorders;
pageStartRow=pageEndRow-pageRecorders;
}
else{
pageEndRow=totalRows;
pageStartRow=pageRecorders*(totalPages-1);
}
SzEmployee[] employees=new SzEmployee[pageEndRow-pageStartRow+1];
// System.out.println("pageStartRow="+pageStartRow);
// System.out.println("pageEndRow="+pageEndRow);
int j=0;
for(int i=pageStartRow;i<pageEndRow;i++)
{
if(i>=0){
SzEmployee employee=(SzEmployee)arrayList.get(i);
employees[j++]=employee;
}
}
this.description();
return employees;
}
public String toString(int temp)
{
String str=Integer.toString(temp);
return str;
}
public void description()
{
String description="共有数据数:"+this.getTotalRows()+
"共有页数: "+this.getTotalPages() +
"当前页数为:"+this.getCurrentPage()+
" 是否有前一页: "+this.isHasPreviousPage() +
" 是否有下一页:"+this.isHasNextPage()+
" 开始行数:"+this.getPageStartRow()+
" 终止行数:"+this.getPageEndRow();
// System.out.println(description);
}
}
分享到:
相关推荐
STRUTS2+HIBERNATE分页 实现代码详细的分页实现代码实现代码详细的分页实现代码实现代码详细的分页实现代码实现代码详细的分页实现代码
Struts+Hibernate实现分页.
本例子用Struts+Hibernate 开发,主要实现分页功能,运行环境Myeclipse+tomcate,附有数据库和jar包。下载后直接运行
用struts+hibernate做的分页显示,我只上传了几个重要的java文件,可以作为参考.
Struts+Hibernate分页标签 Struts+Hibernate分页标签
高效率spring+struts+hibernate分页算法
Struts+Hibernate分页
struts+hibernate分页。采用maysql数据库。采用DAO模式。里面有备份好的数据库
struts+hibernate分页 模糊查询 author:朱千平 phone:13522080786 qq:200896066
Struts+Hibernate分页
struts+hibernate 分页实例
好久没写过什么东西了,最近自己在学习Java WEB方面的东西,自己想用JSP和 Struts2 HIBERNATE来写一个自己工作室的网站练练手,稍微有些收获今天写出来,与大家一起分享一下:STRUTS2+HIBERNATE实现分页是JAVA WEB最...
实现简单的分页功能,用Struts 和hibernate实现
struts+hibernate分页源码!
结合Struts和Hibernate做的一个分页,很完整,可以运行的!
Struts+Hibernate完成分页笔记Struts+Hibernate完成分页笔记Struts+Hibernate完成分页笔记Struts+Hibernate完成分页笔记
Struts+Hibernate+Spring+JS 分页程序,三者的整合应用
struts+spring+hibernate 的一个分页 需要滴拿去
使用Struts + Spring + Hibernate完成分页笔记使用Struts + Spring + Hibernate完成分页笔记使用Struts + Spring + Hibernate完成分页笔记