pageBean实现分页
来源:互联网 发布:星际战甲画质优化 编辑:程序博客网 时间:2024/05/11 00:51
PageBean类
1 package com.xujingyang.domain ; 2 3 import java.util.List ; 4 5 /** 6 * @author oldmonk 7 * @date 2017年4月1日 8 * @param <E> 9 */10 public class PageBean<E> {11 12 private List<E> bean ; // 存放实体类集合13 14 private int currentPage ; // 当前页15 private int pageSize ; // 每页显示的条数16 private int totalPage ; // 总页数17 private int totalCount ; // 总条数18 19 public List<E> getBean() {20 return bean ;21 }22 23 public void setBean(List<E> bean) {24 this.bean = bean ;25 }26 27 public int getCurrentPage() {28 return currentPage ;29 }30 31 public void setCurrentPage(int currentPage) {32 this.currentPage = currentPage ;33 }34 35 public int getPageSize() {36 return pageSize ;37 }38 39 public void setPageSize(int pageSize) {40 this.pageSize = pageSize ;41 }42 43 public int getTotalPage() {44 return (totalCount + pageSize - 1) / pageSize ;45 }46 47 public void setTotalCount(int totalCount) {48 this.totalCount = totalCount ;49 }50 51 }
dao层实现实例
1 /* 根据分类查询信息 2 * @see com.xujingyang.dao.IProductDao#getCurrentPageBean(com.xujingyang.domain.PageBean, java.lang.String) 3 */ 4 @Override 5 public List<Product> getCurrentPageBean(PageBean<Product> pBean, String cid) 6 throws SQLException { 7 QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource()); 8 String sql="SELECT * FROM product WHERE cid=? ORDER BY pdate DESC LIMIT ?,?"; 9 return runner.query(sql, new BeanListHandler<Product>(Product.class),cid,(pBean.getCurrentPage()-1)*pBean.getPageSize(),
pBean.getPageSize());10 }
Service层对PageBean进行封装
1 /* 分页查询 2 * @see com.xujingyang.service.IProductService#getByPage(com.xujingyang.domain.PageBean, java.lang.String) 3 */ 4 @Override 5 public PageBean<Product> getByPage(PageBean<Product> pBean, String cid) throws SQLException { 6 IProductDao dao=(IProductDao) BeanFactory.getBeanClass("ProductDao"); 7 8 //查询总条数 9 int totalCount=dao.getTotalCount(cid);10 11 //查询当前页的数据12 List<Product> lProducts=dao.getCurrentPageBean(pBean,cid);13 14 PageBean< Product> pBean2=new PageBean<Product>();15 pBean2.setTotalCount(totalCount);16 pBean2.setBean(lProducts);17 pBean2.setCurrentPage(pBean.getCurrentPage());18 pBean2.setPageSize(pBean.getPageSize());19 return pBean2;20 }
前台EL表达式分析
1 <!--分页 --> 2 <div style="width:380px;margin:0 auto;margin-top:50px;"> 3 <ul class="pagination" style="text-align:center; margin-top:10px;"> 4 <c:if test="${pBean.currentPage<=1 }"> 5 <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li> 6 </c:if> 7 <c:if test="${pBean.currentPage>1 }"> 8 <li><a href="${pageContext.request.contextPath }/product?method=findByPage¤tPage=${pBean.currentPage-1}&cid=
${pBean.bean[0].cid }" aria-label="Previous"><span aria-hidden="true">«</span></a></li> 9 </c:if>10 11 <!-- <li class="active"><a href="#">1</a></li> -->12 <c:forEach begin="${pBean.currentPage-5>0?pBean.currentPage-5:1}" end=
"${pBean.currentPage+4>pBean.totalPage ?pBean.totalPage:pBean.currentPage+4}" var="i">13 <li><a href="${pageContext.request.contextPath }/product?method=findByPage¤tPage=${i }
&cid=${pBean.bean[0].cid }">${i }</a></li>14 </c:forEach>15 16 <c:if test="${pBean.currentPage>=pBean.totalPage }">17 <li class="disabled">18 <a href="#" aria-label="Next">19 <span aria-hidden="true">»</span>20 </a>21 </li>22 </c:if>23 <c:if test="${pBean.currentPage<pBean.totalPage }">24 <li>25 <a href="${pageContext.request.contextPath }/product?method=findByPage¤tPage=
${pBean.currentPage+1}&cid=${pBean.bean[0].cid }" aria-label="Next">26 <span aria-hidden="true">»</span>27 </a>28 </li>29 </c:if>30 </ul>31 </div>32 <!-- 分页结束======================= -->
阅读全文
0 0
- pageBean实现分页
- 分页的pageBean的实现
- PageBean方式实现分页效果 泽0715
- PageBean方式实现分页效果 &n…
- hibernate+pageBean实现分页dao层功能代码
- struts 分页的pageBean
- 分页jsp PageBean
- 分页中的PageBean
- 用于分页的PageBean
- 分页功能之PageBean
- 自定义分页实例PageBean
- 面向对象的方式来实现分页的功能——分页类PageBean
- 一个通用的分页PageBean
- 分页类PageBean的代码
- PageBean分页类的分装
- 分页中PageBean的创建
- 基于jqGrid实现列表分页效果(后台处理以及pageBean)
- PageBean
- eclipse格式化代码模板
- Apache的DBUtils框架学习(转)
- CC1101Mechester 以及同步字
- mysql数据库备份
- POJ
- pageBean实现分页
- Oracle中主键、外键、索引、序列、唯一性约束的创建
- select下拉联动
- 深入理解多线程,死锁再现
- JavaScript 闭包
- Linux中发布项目的一些命令笔记
- AFNetworking的介绍与使用
- Nginx --Windows下和Linux下搭建集群小记
- 框架之 hibernate简单入门