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框架项目中需要一个分页的功能,查看了很多用一下方式实现,功能思路很清晰,觉得是很好的一种实现方法,记录下便多学习. 刚开始得到 ...
随机推荐
- NodeJS入门学习
node.js 概念:是一个由c++编写的,本质上是一个javascript的运行环境,他可以让js代码运行在服务器端. node可以解析JS代码(没有浏览器安全级的限制) 提供系统级别的API: 1 ...
- 解决:return _compile(pattern, flags).search(string) TypeError: expected string or buffer
今天写爬虫,爬取MM图片页面的标题时,遇到了一个问题,上图: 看看我的代码: import urllib import urllib2 import re class JPMSG: def __ini ...
- svn默认地址老发生改变,记下默认路径
C:\Users\Administrator\AppData\Roaming\Subversion
- centos下 yum安装ngix
1.CentOS 6,先执行:rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6. ...
- php是如何工作的
a:前提条件: apache服务器启动正常工作 b:客户端浏览器在地址栏输入一个程序地栏 按回车发送请求 {请求}http://127.0.0.1/day03/1.php c:apache接收请求,并 ...
- linux C gbk utf-8编码转换
http://blog.csdn.net/sealyao/article/details/5043138
- c++ 修改stl set中的元素
set的迭代器it有const修饰符,那么对它元素的修改就必然不能成功了.但是有时候遇到要修改stl set元素的问题,这个问题一般的解决方法是先erase这个元素,然后再insert,这样效率很低, ...
- jq 侧边栏
HTML 侧边栏HTML代码: <div class="sidebar" id="sucaihuo"> <div class=&quo ...
- [转载]Linux 内核list_head 学习(一)
在Linux内核中,提供了一个用来创建双向循环链表的结构 list_head.虽然linux内核是用C语言写的,但是list_head的引入,使得内核数据结构也可以拥有面向对象的特性,通过使用操作li ...
- MySQL mysqldump 备份脚本(按照db.sql)
mysqldump逻辑备份,按照db.sql文件区分,并压缩 #! /bin/bash #35 02 * * * mysql /data/mysqldata/scripts/mysqldump_per ...