pageBean实现分页
废话不多说,直接上代码!
PageBean类
package com.xujingyang.domain ; import java.util.List ; /**
* @author oldmonk
* @date 2017年4月1日
* @param <E>
*/
public class PageBean<E> { private List<E> bean ; // 存放实体类集合 private int currentPage ; // 当前页
private int pageSize ; // 每页显示的条数
private int totalPage ; // 总页数
private int totalCount ; // 总条数 public List<E> getBean() {
return bean ;
} public void setBean(List<E> bean) {
this.bean = bean ;
} public int getCurrentPage() {
return currentPage ;
} public void setCurrentPage(int currentPage) {
this.currentPage = currentPage ;
} public int getPageSize() {
return pageSize ;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize ;
} public int getTotalPage() {
return (totalCount + pageSize - 1) / pageSize ;
} public void setTotalCount(int totalCount) {
this.totalCount = totalCount ;
} }
dao层实现实例
/* 根据分类查询信息
* @see com.xujingyang.dao.IProductDao#getCurrentPageBean(com.xujingyang.domain.PageBean, java.lang.String)
*/
@Override
public List<Product> getCurrentPageBean(PageBean<Product> pBean, String cid)
throws SQLException {
QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource());
String sql="SELECT * FROM product WHERE cid=? ORDER BY pdate DESC LIMIT ?,?";
return runner.query(sql, new BeanListHandler<Product>(Product.class),cid,(pBean.getCurrentPage()-1)*pBean.getPageSize(),
pBean.getPageSize());
}
Service层对PageBean进行封装
/* 分页查询
* @see com.xujingyang.service.IProductService#getByPage(com.xujingyang.domain.PageBean, java.lang.String)
*/
@Override
public PageBean<Product> getByPage(PageBean<Product> pBean, String cid) throws SQLException {
IProductDao dao=(IProductDao) BeanFactory.getBeanClass("ProductDao"); //查询总条数
int totalCount=dao.getTotalCount(cid); //查询当前页的数据
List<Product> lProducts=dao.getCurrentPageBean(pBean,cid); PageBean< Product> pBean2=new PageBean<Product>();
pBean2.setTotalCount(totalCount);
pBean2.setBean(lProducts);
pBean2.setCurrentPage(pBean.getCurrentPage());
pBean2.setPageSize(pBean.getPageSize());
return pBean2;
}
前台EL表达式分析
<!--分页 -->
<div style="width:380px;margin:0 auto;margin-top:50px;">
<ul class="pagination" style="text-align:center; margin-top:10px;">
<c:if test="${pBean.currentPage<=1 }">
<li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
</c:if>
<c:if test="${pBean.currentPage>1 }">
<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>
</c:if> <!-- <li class="active"><a href="#">1</a></li> -->
<c:forEach begin="${pBean.currentPage-5>0?pBean.currentPage-5:1}" end=
"${pBean.currentPage+4>pBean.totalPage ?pBean.totalPage:pBean.currentPage+4}" var="i">
<li><a href="${pageContext.request.contextPath }/product?method=findByPage¤tPage=${i }
&cid=${pBean.bean[0].cid }">${i }</a></li>
</c:forEach> <c:if test="${pBean.currentPage>=pBean.totalPage }">
<li class="disabled">
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</c:if>
<c:if test="${pBean.currentPage<pBean.totalPage }">
<li>
<a href="${pageContext.request.contextPath }/product?method=findByPage¤tPage=
${pBean.currentPage+1}&cid=${pBean.bean[0].cid }" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</c:if>
</ul>
</div>
<!-- 分页结束======================= -->
pageBean实现分页的更多相关文章
- hibernate+pageBean实现分页dao层功能代码
今天闲来无事,摆弄了一下分页,突然发现很多代码长时间不用就生梳了,虽然有些基础,但没有一篇整合的.这里还是简单示例,主要是以后自己翻着看不用百度找啊找找不到一篇想要的 1.PageBean实体类,一页 ...
- javabean+servlet+jsp实现分页
前端实现用ligerUI实现分页,感觉用框架确实简单,闲着无聊,模拟着liger的分页界面实现了一遍(只要是功能,样式什么无视) 这里用基础的三层架构+servlet+jsp实现,思路很简单,把所有分 ...
- JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能
1 学习计划 1.datagrid使用方法(重要) n 将静态HTML渲染为datagrid样式 n 发送ajax请求获取json数据创建datagrid n 使用easyUI提供的API创建data ...
- 分页技巧_改进JSP页面中的公共分页代码_实现分页时可以有自定义的过滤与排序条件
分页技巧__改进JSP页面中的公共分页代码 自定义过滤条件问题 只有一个url地址不一样写了很多行代码 public>>pageView.jspf添加 分页技巧__实现分页时可以有自定义的 ...
- MyBatis实现拦截器分页功能
1.原理 在mybatis使用拦截器(interceptor),截获所执行方法的sql语句与参数. (1)修改sql的查询结果:将原sql改为查询count(*) 也就是条数 (2)将语句sql进行拼 ...
- javaWeb核心技术第十二篇之分页和条件
分页:limit ?,? 参数1 : startIndex 开始索引. 参数2 : pageSize 每页显示的个数 n 表示第几页 给定一个特殊的单词 pageNumber select * fro ...
- Mybatis动态sql及分页、特殊符号
目的: mybatis动态sql(案例:万能查询) 查询返回结果集的处理 mybatis的分页运用 mybatis的特殊符号 mybatis动态sql(案例:万能查询) 根据id查询 模糊查询 (参数 ...
- javaWeb核心技术之分页和条件
分页:limit ?,? 参数1 : startIndex 开始索引. 参数2 : pageSize 每页显示的个数 n 表示第几页 给定一个特殊的单词 pageNumber select * fro ...
- S2SH项目实现分页功能
javaWEB项目实现分页的方法很多,网上也有很多列子,最近工作中S2SH框架项目中需要一个分页的功能,查看了很多用一下方式实现,功能思路很清晰,觉得是很好的一种实现方法,记录下便多学习. 刚开始得到 ...
随机推荐
- 【译】:lxml.etree官方文档
本文翻译自:http://lxml.de/tutorial.html, 作者:Stefan Behnel 这是一个关于使用lxml.etree进行XML处理的教程.它简要介绍了ElementTree ...
- JAVA中列表,集合之间的区别
整体来看List,Set,Map都是实现了Collection接口的接口. 重复性: List允许存在重复的元素,也就是说List中可以在不影响现有元素的值及其索引的同时插入新的重复元素. Set不允 ...
- ural 2012 About Grisha N.(水)
2012. About Grisha N. Time limit: 1.0 secondMemory limit: 64 MB Grisha N. told his two teammates tha ...
- MySQLDump 备份 Shell 脚本
#!/bin/sh - echo "************************************" echo "----Enterprise Cloud Da ...
- 弹框内画echarts图dom元素无法获取的问题
弹框内画echarts图dom元素无法获取的问题? 什么意思呢?就是当我们打开弹框之后,此时要画eachars图,可是echarts图的容器dom此时为null, 因此我们需要做的就是在dom元素获取 ...
- 按住说话 speex压缩
demo下载 speex要用自己的包名.类名 用ndk-build生成so文件,再删除jni文件使用
- hdu5542 The Battle of Chibi[DP+BIT]
求给定序列中长度为M的上升子序列个数.$N,M<=1000$. 很容易想到方法.$f[i,j]$表示以第$i$个数结尾,长度为$j$的满足要求子序列个数.于是转移也就写出来了$f[i][j]+= ...
- java中获取各种上下文路径的方法小结
一.获得都是当前运行文件在服务器上的绝对路径在servlet里用:this.getServletContext().getRealPath(); 在struts用:this.getServlet(). ...
- python 图形化(Tkinter)
python提供了多个图形开发界面的库,几个常用Python GUI库如下: Tkinter: Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.T ...
- oracle的自增长
mysql的自增长非常容易,一个 AUTO_INCREMENT 就搞定,可是oracle就不行了 下面是oracle的自增长 #创建一个表CREATE TABLE T_TEST_DEPARTMENTS ...