一个通用的jsp分页PageBean
网络编程 2021-07-05 11:23www.168986.cn编程入门
totalRecords 总记录数 list 保存分页的数据 pageNo 当前页
pageSize 页大小 query 保存用户查询的字符串 pageAction 操作分页的Servlet或Action(struts)
package .shap.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;
}
}
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;
}
}
上一篇:jsp网站永久换域名的处理过程
下一篇:通用大型网站页面静态化解决方案
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程