废话不多说,直接上代码!

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">&laquo;</span></a></li>
</c:if>
<c:if test="${pBean.currentPage>1 }">
<li><a href="${pageContext.request.contextPath }/product?method=findByPage&currentPage=${pBean.currentPage-1}&cid=
              ${pBean.bean[0].cid }" aria-label="Previous"><span aria-hidden="true">&laquo;</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&currentPage=${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">&raquo;</span>
</a>
</li>
</c:if>
<c:if test="${pBean.currentPage<pBean.totalPage }">
<li>
<a href="${pageContext.request.contextPath }/product?method=findByPage&currentPage=
                  ${pBean.currentPage+1}&cid=${pBean.bean[0].cid }" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</c:if>
</ul>
</div>
<!-- 分页结束======================= -->

pageBean实现分页的更多相关文章

  1. hibernate+pageBean实现分页dao层功能代码

    今天闲来无事,摆弄了一下分页,突然发现很多代码长时间不用就生梳了,虽然有些基础,但没有一篇整合的.这里还是简单示例,主要是以后自己翻着看不用百度找啊找找不到一篇想要的 1.PageBean实体类,一页 ...

  2. javabean+servlet+jsp实现分页

    前端实现用ligerUI实现分页,感觉用框架确实简单,闲着无聊,模拟着liger的分页界面实现了一遍(只要是功能,样式什么无视) 这里用基础的三层架构+servlet+jsp实现,思路很简单,把所有分 ...

  3. JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能

    1 学习计划 1.datagrid使用方法(重要) n 将静态HTML渲染为datagrid样式 n 发送ajax请求获取json数据创建datagrid n 使用easyUI提供的API创建data ...

  4. 分页技巧_改进JSP页面中的公共分页代码_实现分页时可以有自定义的过滤与排序条件

    分页技巧__改进JSP页面中的公共分页代码 自定义过滤条件问题 只有一个url地址不一样写了很多行代码 public>>pageView.jspf添加 分页技巧__实现分页时可以有自定义的 ...

  5. MyBatis实现拦截器分页功能

    1.原理 在mybatis使用拦截器(interceptor),截获所执行方法的sql语句与参数. (1)修改sql的查询结果:将原sql改为查询count(*) 也就是条数 (2)将语句sql进行拼 ...

  6. javaWeb核心技术第十二篇之分页和条件

    分页:limit ?,? 参数1 : startIndex 开始索引. 参数2 : pageSize 每页显示的个数 n 表示第几页 给定一个特殊的单词 pageNumber select * fro ...

  7. Mybatis动态sql及分页、特殊符号

    目的: mybatis动态sql(案例:万能查询) 查询返回结果集的处理 mybatis的分页运用 mybatis的特殊符号 mybatis动态sql(案例:万能查询) 根据id查询 模糊查询 (参数 ...

  8. javaWeb核心技术之分页和条件

    分页:limit ?,? 参数1 : startIndex 开始索引. 参数2 : pageSize 每页显示的个数 n 表示第几页 给定一个特殊的单词 pageNumber select * fro ...

  9. S2SH项目实现分页功能

    javaWEB项目实现分页的方法很多,网上也有很多列子,最近工作中S2SH框架项目中需要一个分页的功能,查看了很多用一下方式实现,功能思路很清晰,觉得是很好的一种实现方法,记录下便多学习. 刚开始得到 ...

随机推荐

  1. 【VS2013编译DirectX Tutorials时遇到的错误】"const wchar_t *" 类型的实参与 "LPCSTR" 类型的形参不兼容

    本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/3696367.html 通过查看LPCSTR的定义: typedef _Null_te ...

  2. Python学习之路day4-列表生成式、生成器、Iterable和Iterator

    一.列表生成式 顾名思义,列表生成式就是用于生成列表的特殊语法形式的表达式. 1.1 语法格式 [exp for iter_var in iterable] 工作过程: 1.通过iter_var迭代i ...

  3. selenium-webdirver api-定位方式

    1,8种单数定位方式 # 通过ID定位目标元素 driver.find_element_by_id('i1') # 通过className定位目标元素 driver.find_element_by_c ...

  4. uuid 学习

    #include <vector> #include <iostream> #include <boost/uuid/uuid.hpp> #include < ...

  5. CodeForces - 154C:Double Profiles (hash+排序)

    You have been offered a job in a company developing a large social network. Your first task is conne ...

  6. 如何加快Json 序列化?有哪些方法?

    1.使用阿里的fastjson 2.可以通过去除不必要属性加快序列化.如person对象,有id,name,address,我json需要用户姓名,此时序列化的时候就只序列化name,id和addre ...

  7. @Override重写

    package com.wisezone.f; //父类 public class Person { //姓名 private String name; //年龄 private int age; / ...

  8. LeetCode Longest Harmonious Subsequence

    原题链接在这里:https://leetcode.com/problems/longest-harmonious-subsequence/description/ 题目: We define a ha ...

  9. Httpclient远程调用WebService示例

    我们将Web Service发布在Tomcat或者其他应用服务器上后,有很多方法可以调用该Web Service,常用的有两种: 1.通过浏览器HTTP调用,返回规范的XML文件内容      2.通 ...

  10. Maven里头的pom.xml配置详解

    正常的pom配置文件如下所示: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http ...