pageHelper分页
引入jar包
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.0</version>
</dependency> <!--解决pagehelper分页警告 -->
<!-- <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.4.2-fix</version>
</dependency> -->
前台分页
<div class="col-md-12 text-center">
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="/details?${detail.id}?pn=1" aria-label="First">
<span aria-hidden="true">首页</span>
</a>
</li> <c:if test="${pageInfo.hasPreviousPage}">
<li >
<a href="/details?${detail.id}?pn=${pageInfo.pageNum-1}" aria-label="Previous">
<span aria-hidden="true">上一页</span>
</a>
</li>
</c:if>
<c:if test="${!pageInfo.hasPreviousPage}">
<li >
<a href="#" aria-label="Previous">
<span aria-hidden="true">上一页</span>
</a>
</li>
</c:if> <!--循环遍历连续显示的页面,若是当前页就高亮显示,并且没有链接-->
<c:forEach items="${pageInfo.navigatepageNums}" var="page_num">
<c:if test="${page_num == pageInfo.pageNum}">
<li class="active"><a href="#">${page_num}</a></li>
</c:if>
<c:if test="${page_num != pageInfo.pageNum}">
<li><a href="/details?${detail.id}?pn=${page_num}">${page_num}</a></li>
</c:if>
</c:forEach>
<c:if test="${pageInfo.hasNextPage}">
<li>
<a href="/details?${detail.id}?pn=${pageInfo.pageNum+1}" aria-label="Next">
<span aria-hidden="true">下一页</span>
</a>
</li>
</c:if>
<c:if test="${!pageInfo.hasNextPage}">
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">下一页</span>
</a>
</li>
</c:if>
<li>
<a href="/details?${detail.id}?pn=${pageInfo.pages}" aria-label="Last">
<span aria-hidden="true">尾页</span>
</a>
</li>
</ul>
</nav> <!-- <div style="text-align: center;">
<ul id="pagination" class="pagination"></ul>
</div> -->
</div>
Controller
@RequestMapping("/details")
public String webdetail(Model model,@RequestParam(required = false,defaultValue = "1",value = "pn")Integer pn)throws Exception {
PageInfo pageInfo = detailService.commentList(pn);
model.addAttribute("pageInfo", pageInfo);
return "details";
}
Service
@Override
public PageInfo commentList(Integer pn) throws Exception { //引入分页查询,使用PageHelper分页功能
//在查询之前传入当前页,然后多少记录
PageHelper.startPage(pn,5);
//startPage后紧跟的这个查询就是分页查询
CommentExample example = new CommentExample();
List<Comment> emps = commentMapper.selectByExample(example);
//使用PageInfo包装查询结果,只需要将pageInfo交给页面就可以
PageInfo pageInfo = new PageInfo<>(emps,5);
//pageINfo封装了分页的详细信息,也可以指定连续显示的页数 return pageInfo; }
pageHelper分页的更多相关文章
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- PageHelper分页插件的使用
大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...
- SpringBoot整合系列-PageHelper分页插件
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- 记录pageHelper分页orderby的坑
pageHelper的count查询会过滤查询sql中的order by条件! pageHelper分页功能很强大,如果开启count统计方法,在你执行查询条件时会再执行一条selet count(* ...
- mybatis pagehelper分页插件使用
使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...
- spring boot 整合pagehelper分页插件
Spring Boot 整合pagehelper分页插件 测试环境: spring boot 版本 2.0.0.M7 mybatis starter 版本 1.3.1 jdk 1.8 ------ ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- 求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
存储过程如下: dao层的sql Controller层调用: html页面 没有使用pagehelper分页之前,可以正常使用 使用了pagehelper之后就报错 ### Error queryi ...
随机推荐
- postgresql-定时备份,压缩备份
crontab -e 在最后添加: # backup database at 22:00 every day 0 22 * * * thunisoft /home/eric/bin/backup-db ...
- 上台阶问题(递归,DFS)
题目 一共39层台阶.如果我每一步迈上1个台阶或者两个台阶,先迈左脚,再迈右脚,然后左右交换,最后一步迈右脚,也就是一共要走偶数步,那么,上完39级台阶,有多少种不同的方法? 思路 采用递归的思想,边 ...
- Oracle 11g安装时针对不同操作系统所需的依赖包查询地址
http://docs.oracle.com/cd/E11882_01/install.112/e24326/ 点击连接,出现页面,往下滑动:)
- Mysql 索引原理及优化
本文内容主要来源于互联网上主流文章,只是按照个人理解稍作整合,后面附有参考链接. 一.摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引 ...
- tensorflow进阶篇-4(损失函数2)
Hinge损失函数主要用来评估支持向量机算法,但有时也用来评估神经网络算法.下面的示例中是计算两个目标类(-1,1)之间的损失.下面的代码中,使用目标值1,所以预测值离1越近,损失函数值越小: # U ...
- let'encript 解决证书问题
今天服务器let'encript证书过期了,年纪大了老忘,不得不把别人的博客看一遍,就是因为我不想定时任务执行acme_tiny.py,还是写个文档记下,很久不写对外博客了,冒个泡. 1.创建普通域名 ...
- spring-如何将spring源码成功导入Eclipse中
一.从 github上下载Spring源码到本机 二.利用 Gradle 编译 Spring 源码 环境: - Spring源码版本:spring-framework-4.3.x - Gradle版本 ...
- flex布局中transform出错
在flex布局下,若应用transform 的动画的子元素没有使用进行定位,则动画过程中,子元素将相对display:flex的元素进行static定位 动画结束后位置正常: 修复代码只需要posit ...
- RESTful SOA与DDD(领域驱动设计)
视频地址:http://www.infoq.com/presentations/RESTful-SOA-DDD 作者的一个DDD采访:http://www.informit.com/articles/ ...
- jquery控制input只能输入数字和两位小数
jquery代码 function num(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字" ...