一個通用的jsp分頁PageBean_JSP編程

來源:互聯網
上載者:User
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;
}
}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.