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框架项目中需要一个分页的功能,查看了很多用一下方式实现,功能思路很清晰,觉得是很好的一种实现方法,记录下便多学习. 刚开始得到 ...
随机推荐
- iTerm2 + Oh My Zsh
iTerm2 http://iterm2.com/downloads.html https://iterm2.com/downloads/stable/iTerm2-2_1_4.zip Oh My Z ...
- 详解 Android 通信
详解 Android 通信 :http://www.androidchina.net/5028.html
- angular复选框式js树形菜单(一)
treeView.html <ul class="tree-view"> <li ng-repeat="item in treeData" n ...
- mxnet(gluon)—— 模型、数据集、损失函数、优化子等类、接口大全
1. 数据集 dataset_train = gluon.data.ArrayDataset(X_train, y_train) data_iter = gluon.data.DataLoader(d ...
- Python 中的几种矩阵乘法 np.dot, np.multiply, *
使用array时,运算符 * 用于计算数量积(点乘),函数 dot() 用于计算矢量积(叉乘).使用matrix时,运算符 * 用于计算矢量积,函数 multiply() 用于计算数量积. 下面是使用 ...
- 取余运算(mod)(分治)
[问题描述] 输入b,p,k的值,求bp mod k的值.其中b,p,k*k为长整形数. [输入样例]mod.in 2 10 9 [输出样例]mod.out ...
- file“xxxxx”has modification times xxxxx s in the future..
这是因为一个项目从一个电脑拷贝的到另一个电脑上时,两个电脑的时钟不一致所致,修改一下项目所在目录的修改时间即可: find /your/dir -type f -exec touch {} + 也可以 ...
- 四、ABP 学习系列 - 配置Swagger
一.再XX.Web项目中用Nuget安装Swashbuckle.AspNetCore.SwaggerGen和Swashbuckle.AspNetCore.SwaggerUI 二.在Startup.cs ...
- Day3-Python基础3--局部变量和全局变量
一.局部变量 def test(name): print("before change:",name) name = "maqing" #局部变量name,只能 ...
- Spark Tungsten in-heap / off-heap 内存管理机制--待整理
一:Tungsten中到底什么是Page? 1. 在Spark其实不存在Page这个类的.Page是一种数据结构(类似于Stack,List等),从OS层面上讲,Page代表了一个内存块,在Page里 ...