分页查询

1 // 动态分页
2     public List<Remotecertapplyorder> findPage(String hqlBuffer, int PageSize,
3             int PageNo);
4     // 获得总记录数
5     public int getCount(String hqlBuffer);
 1 @SuppressWarnings("unchecked")
 2     @Override
 3     public List<Remotecertapplyorder> findPage(String hqlBuffer, int PageNo,
 4             int PageSize)
 5     {
 6         Query query = getHibernateTemplate().getSessionFactory()
 7                 .getCurrentSession().createQuery(hqlBuffer);
 8         query.setFirstResult((PageNo - 1) * PageSize);
 9         query.setMaxResults(PageSize);
10         return query.list();
11     }
12 
13     // 获得总记录数
14     @Override
15     public int getCount(String hqlBuffer)
16     {
17         Query query = getHibernateTemplate().getSessionFactory()
18                 .getCurrentSession().createQuery(hqlBuffer);
19         return query.list().size();
20     }
1     // 查询用户对应的订单
2     public PaginationSupport<Remotecertapplyorder> getorder(Integer userid, String userName,
3             Date beginTime, Date endTime, int currPageNo, int pageSize);
 1 // 查询用户申请的订单
 2     @Override
 3     public PaginationSupport<Remotecertapplyorder> getorder(Integer userid,
 4             String userName, Date beginTime, Date endTime, int currPageNo,
 5             int pageSize) // 得到订单
 6     {
 7         RemotecertapplyorderDao remotecertapplyorderDao = (RemotecertapplyorderDao) dao;
 8         PaginationSupport<Remotecertapplyorder> result = new PaginationSupport<Remotecertapplyorder>();
 9 
10         if (currPageNo > 0)
11         {
12             result.setCurrPageNo(currPageNo);
13         }
14 
15         if (pageSize > 0)
16         {
17             result.setPageSize(pageSize);
18         }
19 
20         StringBuffer hqlBuffer = new StringBuffer(
21                 "select distinct ro from Remotecertapplyorder ro left join fetch ro.remotecertapplies r "
22                         + " where ro.applicant.id = " + userid);
23 
24         if (userName != null && userName.length() > 0)
25         {
26             hqlBuffer.append("and(r.username like '%" + userName
27                     + "' or r.invoicename like '%" + userName + "')");
28         }
29 
30         if (beginTime != null)
31         {
32             hqlBuffer.append(" and r.createtime >= '" + beginTime + "' ");
33         }
34         if (endTime != null)
35         {
36             hqlBuffer.append(" and r.createtime <= '" + endTime + "' ");
37         }
38 
39         int count = remotecertapplyorderDao.getCount(hqlBuffer.toString());
40         result.setTotalCount(count);
41         if (count != 0)
42         {
43             if (result.getTotalPageCount() < currPageNo)
44             {
45                 currPageNo = result.getTotalPageCount();
46                 result.setCurrPageNo(currPageNo);
47             }
48             List<Remotecertapplyorder> list = remotecertapplyorderDao.findPage(
49                     hqlBuffer.toString(), result.getPageSize(),
50                     result.getCurrPageNo());
51             result.setItems(list);
52         }
53         return result;
54     }
 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
 3 <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 5 <html>
 6 <body>
 7     <div class="page-bar">
 8         <c:if test="${param.currentPageNo>1}">
 9             <a href="javascript:page_nav(${param.formName},1);">首页</a>
10             <a
11                 href="javascript:page_nav(${param.formName},<c:out value="${param.currentPageNo-1}"/>);">上一页</a>
12         </c:if>
13         <c:if test="${currentPageNo<=1}">
14         首页&nbsp;&nbsp;上一页
15     </c:if>
16         <c:if test="${param.currentPageNo<param.totalPageCount}">
17             <a
18                 href="javascript:page_nav(${param.formName},<c:out value="${param.currentPageNo+1}" />);">下一页</a>
19             <a
20                 href="javascript:page_nav(${param.formName},<c:out value="${param.totalPageCount}"/>);">最后一页</a>
21         </c:if>
22         <c:if test="${param.currentPageNo>=param.totalPageCount}">
23         下一页&nbsp;&nbsp;尾页
24     </c:if>
25         &nbsp;&nbsp; &nbsp;&nbsp;第
26         ${param.currentPageNo}页/共${param.totalPageCount}页&nbsp;&nbsp;共${param.totalRecordCount
27     }条记录
28         &nbsp;&nbsp; &nbsp;&nbsp;<input class="gopage" size="5" type="text"
29             value="${param.currentPageNo }" /> <input type="button" value="跳转"
30             οnclick="jump_to()" /> &nbsp;&nbsp; &nbsp;&nbsp; <select name="sel"
31             id="sel" style="width:65px" onFocus="Myselect()">
32         </select>
33         </form>
34     </div>
35 </body>
36 </html>
1 <input type="hidden"
2                 name="currentPageNo" value="1" /> <input type="hidden"
3                 name="pageSize" value="1" /> <input type="hidden"
4                 name="totalPageCount" value="${orderList.totalPageCount}" />
1 <div class="page">
2             <c:import url="rollPage.jsp" charEncoding="UTF-8">
3                 <c:param name="formName" value="document.forms[0]" />
4                 <c:param name="totalRecordCount" value="${orderList.totalCount}" />
5                 <c:param name="totalPageCount" value="${orderList.totalPageCount}" />
6                 <c:param name="currentPageNo" value="${orderList.currPageNo}" />
7             </c:import>
8         </div>

 

转载于:https://www.cnblogs.com/jinhuan/p/6813241.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值