程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> 一個通用的jsp分頁PageBean

一個通用的jsp分頁PageBean

編輯:關於JSP
package com.shaccp.web.util;
import java.util.List;
public class PageBean {
/**
*
*
* @author ppy 2008-10-18 14:3:56
* totalRecords 總記錄數
* list 保存分頁的數據
* pageNo 當前頁
* pageSize 頁大小
* query 保存用戶查詢的字符串
* pageAction 操作分頁的Servlet或Action(struts)
* method (struts中Action對應的method)
*
*
*/
private int totalRecords;
private List list;
private int pageNo;
private int pageSize;
private String query;
private String pageAction;
private String method;
public void setPageAction(String pageAction) {
this.pageAction = pageAction;
}
public void setMethod(String method) {
this.method = method;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public void setQuery(String query) {
this.query = query;
}
/**
* 取得總頁數的方法 return
* totalRecords%pageSize==0?(totalRecords/pageSize):(totalRecords/pageSize+1)
*
* @return
*/
public int getTotalPages() {
return (totalRecords + pageSize - 1) / pageSize;
}
/**
* 得到首頁
*
* @return
*/
public int getTopPage() {
return 1;
}
/**
* 得到上一頁
*
* @return
*/
public int getPreviousPageNo() {
if (pageNo <= 1)
return 1;
else
return (pageNo - 1);
}
/**
* 得到下一頁
*
* @return
*/
public int getNextPageNo() {
if (pageNo >= getTotalPages()) {
return getTotalPages() == 0 ? 1 : getTotalPages();
} else {
return pageNo + 1;
}
}
/**
* 得到尾頁
*
* @return
*/
public int getBottomPageNo() {
return getTotalRecords() == 0 ? 1 : getTotalPages();
}
//頁面分頁導航的鏈接 方式一
public String getPageToolBar1() {
String str = "";
str += "<a href='" + pageAction + "?method=" + method + "&userQuery="
+ query + "&pageNo=" + getPreviousPageNo() + "&pageSize="
+ pageSize + "'>上一頁</a> ";
str += "<a href='" + pageAction + "?method=" + method + "&userQuery="
+ query + "&pageNo=" + getNextPageNo() + "&pageSize="
+ pageSize + "'>下一頁</a>";
return str;
}
//頁面分頁導航的鏈接 方式二
public String getPageToolBar2() {
String str = "";
int pageSplit = (pageNo / 5) * 5;
for (int i = pageSplit - 1; i < (pageSplit + 6); i++) {
if (i <= 0) {
} else if (pageNo == i) {
str += i + " ";
} else if (i > getTotalPages()) {
} else {
str += "<a href='" + pageAction + "?method=" + method
+ "&userQuery=" + query + "&pageNo=" + i + "&pageSize="
+ pageSize + "'>" + i + "</a>" + " ";
}
}
return str;
}
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved