如何使用pagebean进行查询及翻页

wxl8023 2008-10-15 07:40:26
如何使用pagebean进行查询及翻页,最好能提供一个小例子,谢谢!
...全文
147 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lihan6415151528 2008-10-15
  • 打赏
  • 举报
回复
package com.lhkj.util.beans;

public class Page {
private int pagesize;
private int startnum;

public Page(int startnum,int size){
this.startnum=startnum;
this.pagesize=size;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getStartnum() {
return startnum;
}
public void setStartnum(int startnum) {
this.startnum = startnum;
}
}


action里面

// 从页面获得偏移量
Integer pagesize=30;

session.setAttribute("pagesize", pagesize);

// 从页面获得偏移量
String offset = request.getParameter("pager.offset");

if (offset == null) {
// 第一次查询,需要查出记录总数
String count = "";
count = this.technologyStoreService
.findTechByisAuditSharePageNum(2).toString();
// 只需要下传页面总记录数,每页记录数即可。
session.setAttribute("resultSize", count);
}

if (offset == null || offset.equals("")) {
offset = "0";
}
int intoffset = 0;
if (offset != null && !offset.equals("")) {
intoffset = Integer.parseInt(offset);
}

final Page page = new Page(intoffset, pagesize);
session.setAttribute("pagesize", pagesize);
// 查询处索要的list
List tmp = this.technologyStoreService
.findTechByisAuditSharePage(2, page);
session.setAttribute("slist", tmp);




jsp里面



<pg:pager items="${sessionScope.resultSizeDetail }"
maxPageItems="${requestScope.pagesizeDetail}"
maxIndexPages="<%=10%>" isOffset="<%=true%>"
url="/lhkjywgl/technologyStore/addTechnologyStore.do"
export="offset,currentPageNumber=pageNumber"
scope="request">
<pg:param name="operate" value="detail"></pg:param>
<pg:param name="technologyStore1"
value="${technologyStore1}"></pg:param>
<pg:param name="recopyId" value="${recopyId}"></pg:param>
<pg:param name="recopyIdd" value="${recopyIdd}"></pg:param>
<pg:param name="id" value="${id}"></pg:param>
<pg:param name="op" value="op"></pg:param>
<pg:param name="niming" value="0"></pg:param>
<jsp:include page="/plugins/paging/jsp/altavista.jsp"
flush="true" />
<!-- 从page对象中取得属性值firstItem , lastIterm -->
<pg:page export="firstItem, lastItem">
<font color="red">本页 <strong><%=firstItem%>
</strong> -- <strong> <%=lastItem%> </strong>条 <strong>/</strong>
总记录数 <strong><bean:write name="resultSizeDetail" />
</strong>条 </font>
</pg:page>
</pg:pager>


楼主参考!

/* * @(#)PageControl.java 1.00 2004-9-22 * * Copyright 2004 2004 . All rights reserved. * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.hexiang.utils; /** * PageControl, 分页控制, 可以判断总页数和是否有上下页. * * 2008-07-22 加入输出上下分页HTML代码功能 * * @author HX * @version 1.1 2008-9-22 */ public class PageBean { /** 每页显示记录数 */ private int pageCount; /** 是否有上一页 */ private boolean hasPrevPage; /** 记录总数 */ private int recordCount; /** 是否有下一页 */ private boolean hasNextPage; /**总页面数 */ private int totalPage; /** 当前页码数 */ private int currentPage; /** * 分页前的页面地址 */ private String pageUrl; /** * 输出分页 HTML 页面跳转代码, 分链接和静态文字两种. * 2008-07-22 * @return HTML 代码 */ public String getPageJumpLinkHtml() { if(StringUtil.isEmpty(pageUrl)) { return ""; } // 检查是否有参数符号, 没有就加上一个? if(pageUrl.indexOf('?') == -1) { pageUrl = pageUrl + '?'; } StringBuffer buff = new StringBuffer(""); // 上一页翻页标记 if(currentPage > 1) { buff.append("[ 上一页 ] "); } else { buff.append("[ 上一页 ] "); } // 下一页翻页标记 if(currentPage < getTotalPage()) { buff.append("[ 下一页 ] "); } else { buff.append("[ 下一页 ] "); } buff.append(""); return buff.toString(); } /** * 输出页码信息: 第${currentPage}页/共${totalPage}页 * @return */ public String getPageCountHtml() { return "第" + currentPage + "页/共" + getTotalPage() + "页"; } /** * 输出 JavaScript 跳转函数代码 * @return */ public String getJavaScriptJumpCode() { if(StringUtil.isEmpty(pageUrl)) { return ""; } // 检查是否有参数符号, 没有就加上一个? if(pageUrl.indexOf("?") == -1) { pageUrl = pageUrl + '?'; } return "<script>" + "// 页面跳转函数\n" + "// 参数: 包含页码的表单元素,例如输入框,下拉框等\n" + "function jumpPage(input) {\n" + " // 页码相同就不做跳转\n" + " if(input.value == " + currentPage + ") {" + " return;\n" + " }" + " var newUrl = '" + pageUrl + "&page=' + input.value;\n" + " document.location = newUrl;\n" + " }\n" + " 转到 输入页码: * @return */ public String getPageFormJumpHtml() { String s = "转到\n" + "\t \n" + " \n" + " 输入页码:Page + "\" id=\"jumpPageBox\" size=\"3\"> \n" + " Page(document.getElementById('jumpPageBox'))\"> "; return s; } /** * 进行分页计算. */ private void calculate() { if (getPageCount() == 0) { setPageCount(1); } totalPage = (int) Math.ceil(1.0 * getRecordCount() / getPageCount()); // 总页面数 if (totalPage == 0) totalPage = 1; // Check current page range, 2006-08-03 if(currentPage > totalPage) { currentPage = totalPage; } // System.out.println("currentPage=" + currentPage); // System.out.println("maxPage=" + maxPage); // // Fixed logic error at 2004-09-25 hasNextPage = currentPage < totalPage; hasPrevPage = currentPage > 1; return; } /** * @return Returns the 最大页面数. */ public int getTotalPage() { calculate(); return totalPage; } /** * @param currentPage * The 最大页面数 to set. */ @SuppressWarnings("unused") private void setTotalPage(int maxPage) { this.totalPage = maxPage; } /** * 是否有上一页数据 */ public boolean hasPrevPage() { calculate(); return hasPrevPage; } /** * 是否有下一页数据 */ public boolean hasNextPage() { calculate(); return hasNextPage; } // Test public static void main(String[] args) { PageBean pc = new PageBean(); pc.setCurrentPage(2); pc.setPageCount(4); pc.setRecordCount(5); pc.setPageUrl("product/list.do"); System.out.println("当前页 " + pc.getCurrentPage()); System.out.println("有上一页 " + pc.hasPrevPage()); System.out.println("有下一页 " + pc.hasNextPage()); System.out.println("总页面数 " + pc.getTotalPage()); System.out.println("分页 HTML 代码 " + pc.getPageJumpLinkHtml()); } /** * @return Returns the 当前页码数. */ public int getCurrentPage() { return currentPage; } /** * 设置当前页码, 从 1 开始. * @param currentPage * The 当前页码数 to set. */ public void setCurrentPage(int currentPage) { if (currentPage <= 0) { currentPage = 1; } this.currentPage = currentPage; } /** * @return Returns the recordCount. */ public int getRecordCount() { return recordCount; } /** * @param recordCount * The recordCount to set. */ public void setRecordCount(int property1) { this.recordCount = property1; } /** * @return Returns the 每页显示记录数. */ public int getPageCount() { return pageCount; } /** * @param pageCount * The 每页显示记录数 to set. */ public void setPageCount(int pageCount) { this.pageCount = pageCount; } public String getPageUrl() { return pageUrl; } public void setPageUrl(String value) { pageUrl = value; } }

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧