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框架项目中需要一个分页的功能,查看了很多用一下方式实现,功能思路很清晰,觉得是很好的一种实现方法,记录下便多学习. 刚开始得到 ...
随机推荐
- Mac的搜狗输入法和QQ输入法加入⌘⌥⌃⇧自定义短语
搜狗输入法(Mac):http://pinyin.sogou.com/mac/ 创建名为『搜狗输入法自定义短语.ini』的文本文件(建议用Sublime Text),内容如下,然后偏好设置的自定义短语 ...
- 如何关闭Windows10系统更新
单击左下角开始菜单点击设置图标进入设置界面 在设置窗口中输入“服务”搜索 在结果中选择查看本地服务 在服务列表中找到windows update服务双击它 点击停止按钮先停止该服务,稍等片 ...
- Chrome Adobe flash player已过期怎么办
越来越多的朋友感受到了来自谷歌chrome新版浏览器的压力,因为有不少朋友在使用新版chrome浏览器看视频时,却出现了这样的提示:Adobe flash player已过期!怎么办啊? 有网友抱怨: ...
- Spring_总结_02_依赖注入
一.前言 本文承接上一节:Spring_总结_01_Spring概述 在上一节中,我们了解了Spring的最根本使命.四大原则.六大模块以及Spring的生态. 这一节我们开始了解Spring的第二大 ...
- mysql数据库乱码问题
设置如下:SET character_set_client=utf8; SET character_set_results=utf8; SET character_set_connection=utf ...
- MySQL引擎各个引擎对比介绍
1.什么是存储引擎? 存储引擎类似于录制的视频文件,可以转换成不同的格式,如MP4,avi等格式,而存储在我们的磁盘上也会存在于不同类型的文件系统中如:Windows里常见的NTFS,fat32等.存 ...
- PHP提供的数组比较函数总结
在我们看PHP手册的时候发现,PHP提供了许多数组元素比较的函数,看起来又多又烦又不好记,现在我们来总结一下: sort() — 本函数对数组进行排序,当本函数结束时数组单元将被从最低到最高重新安排. ...
- HDU - 6191 Query on A Tree (可持久化字典树/字典树合并)
题目链接 题意:有一棵树,树根为1,树上的每个结点都有一个数字x.给出Q组询问,每组询问有两个值u,x,代表询问以结点u为根的子树中的某一个数与x的最大异或值. 解法一:dfs序+可持久化字典树.看到 ...
- qduoj su003 数组合并
描述 现在呢有两个整形数组,a[n]和b[m],而且已经知道这两个数组都是非降序数组.现在呢就有一个工作需要你来完成啦.对于a中的每个元素a[i]在b中寻找<=a[i] 的元素个数,个数记为x[ ...
- npm镜像安装
安装淘宝NPM镜像 https://npm.taobao.org/ npm install -g cnpm --registry=https://registry.npm.taobao.org 配置 ...