分页java代码 分页 java

如何用java实现分页效果(eclipse工具)package dl.wsxx.base;
public class Pager {
private int totalRows; // 总行数
private int pageSize; // 每页显示的行数
private int currentPage; // 当前页号
private int totalPages; // 总页数
private int startRow; // 当前页在数据库中的起始行
private int pageStartRow; // 当前页开始行
private int pageEndRow; // 当前页结束行
private int hasNextPage; // 下一页存在标识[0:不存在,1:存在]
private int hasPreviousPage; // 前一页存在标识[0:不存在,1:存在]
public Pager() {
}
public Pager(int _totalRows,int _pageSize) {
pageSize = _pageSize;
totalRows = _totalRows;
totalPages = totalRows / pageSize;
int mod = totalRows % pageSize;
if (mod0) {
totalPages++;
}
currentPage = 1;
startRow = 0;
}
public int getStartRow() {
return startRow;
}
public int getpageStartRow() {
return pageStartRow;
}
public int getpageEndRow() {
return pageEndRow;
}
public int getTotalPages() {
return totalPages;
}
public int getCurrentPage() {
return currentPage;
}
public int getPageSize() {
return pageSize;
}
public int getHasNextPage() {
return hasNextPage;
}
public int getHasPreviousPage() {
return hasPreviousPage;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public void setPageStartRow(int pageStartRow) {
this.pageStartRow = pageStartRow;
}
public void setPageEndRow(int pageEndRow) {
this.pageEndRow = pageEndRow;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public void setHasNextPage(int hasNextPage) {
this.hasNextPage = hasNextPage;
}
public void setHasPreviousPage(int hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public int getTotalRows() {
return totalRows;
}
public void first() {
currentPage = 1;
startRow = 0;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void previous() {
if (currentPage == 1) {
return;
}
currentPage--;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void next() {
if (currentPagetotalPages) {
currentPage++;
}
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void last() {
currentPage = totalPages;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void refresh(int _currentPage) {
currentPage = _currentPage;
if (currentPagetotalPages) {
last();
}
this.hasFlagSet(currentPage, totalPages);
}
private void hasFlagSet(int currentPage, int totalPages) {

推荐阅读