日期:2014-05-18  浏览次数:20737 次

50分求一个jsp的分页方法,jdbc--sql2000
如题

------解决方案--------------------
up
------解决方案--------------------
友情帮顶
------解决方案--------------------
package com.ts;


import java.util.ArrayList;
import java.util.List;


public class PageInfo {

List arrayList;
List pagelist;

//分页信息定义
int totalRows = 0; //总数据数
int pageRecorders = 20;//每页显示记录数
public int totalPages = 0; //总页数
int pageStartRow = 0;//每页的起始数
int pageEndRow = 0; //每页显示数据的终止数
int currentPage = 1;//当前页
boolean hasNextPage = false; //是否有下一页
boolean hasPreviousPage = false; //是否有前一页

public int getTotalRows() {
return totalRows;
}

public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}

public int getPageRecorders() {
return pageRecorders;
}

public void setPageRecorders(int pageRecorders) {
this.pageRecorders = pageRecorders;
}

public int getTotalPages() {
return totalPages;
}

public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}

public int getPageStartRow() {
return pageStartRow;
}

public void setPageStartRow(int pageStartRow) {
this.pageStartRow = pageStartRow;
}

public int getPageEndRow() {
return pageEndRow;
}

public void setPageEndRow(int pageEndRow) {
this.pageEndRow = pageEndRow;
}

public int getCurrentPage() {
return currentPage;
}

public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}

public boolean isHasNextPage() {
return hasNextPage;
}

public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}

public boolean isHasPreviousPage() {
return hasPreviousPage;
}

public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}

//创建初始化对象
public PageInfo(List arrayList,int pageRecorders) {

this.arrayList = arrayList;
this.pageRecorders=pageRecorders;
totalRows = arrayList.size();//获得总数据数

//获得总页数
if ((totalRows % pageRecorders) == 0) {
totalPages = totalRows / pageRecorders;
} else {
totalPages = totalRows / pageRecorders + 1;
}
totalPages = (totalPages==0)? 1 : totalPages;

//设置第一页开始位置和结束位置
if (totalRows < pageRecorders) {
this.pageStartRow = 0;
this.pageEndRow = totalRows;
} else {
this.pageStartRow = 0;
this.pageEndRow = pageRecorders;
}

//是否有下一页
if (currentPage > = totalPages) {
hasNextPage = false;
} else {
hasNextPage = true;
}

}

//转到页面
public List getPageList(int currentPage) {

if (currentPage <= 0) {
currentPage = 1;
}

if (currentPage > = totalPages) {