spring_boot 中通过PageHelper分页
1. 第一步
导入pom.xml依赖
<!--PageHelper模版-->
<!--PageHelper模版-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
2.第二步
对application.properties进行配置(为了不让缓存,在开发时可以关闭缓存:spring.thymeleaf.cache=false)
#设置分页
#分页插件
pagehelper.helper-dialect=mysql
pagehelper.params=count=countSql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
3.第三步
在controller层使用分页插件,见代码!
@Controller
public class ProviderController { Logger logger = LoggerFactory.getLogger(getClass()); @Autowired
ProviderDao dao; @Autowired
ProviderMapper providerMapper; @GetMapping("/providers")
public String list(Map<String ,Object> map, Provider provider, @RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum){
//分页为八条一页
PageHelper.startPage(pageNum,8); //查询数据库获取所有供应商
List<Provider> providers = providerMapper.getProviders(provider); PageInfo<Provider> pageInfo = new PageInfo<Provider>(providers); map.put("pageInfo",pageInfo); return "provider/list";
}
}
4.前端使用thymeleaf模板进行数据解析(*.html文件)
<table class="providerTable" cellpadding="0" cellspacing="0" >
<tr class="firstTr">
<th width="10%">供应商编码</th>
<th width="20%">供应商名称</th>
<th width="10%">联系人</th>
<th width="10%">联系电话</th>
<th width="10%">传真</th>
<th width="10%">创建时间</th>
<th width="30%">操作</th>
</tr>
<tr th:each="p: ${pageInfo.list}">
<td th:text="${p.pid}">PR</td>
<td th:text="${p.providerName}">001</td>
<td th:text="${p.people}"></td>
<td th:text="${p.phone}">15918230478</td>
<td th:text="${p.fax}">15918230478</td>
<td th:text="${#dates.format(p.createDate,'yyyy-MM-dd')}">2015-11-12</td>
<td>
<a th:href="@{/provider/}+${p.pid}" href="view.html"><img th:src="@{/img/read.png}" alt="查看" title="查看"/></a>
<a th:href="@{/provider/}+${p.pid}+'?type=update'" href="update.html"><img th:src="@{/img/xiugai.png}" alt="修改" title="修改"/></a>
<!-- 绑定属性 -->
<a th:attr="del_uri=@{/provider/}+${p.pid}" href="#" class="delete"><img th:src="@{/img/schu.png}" alt="删除" title="删除"/></a>
</td>
</tr> <tr class="firstTr" style="color: blue">
<th width="10%"> ------=--</th>
<th width="20%"> ----=-----</th>
<th width="30%"><p style="color: blue">当前 <span th:text="${pageInfo.pageNum}"></span> 页,总 <span th:text="${pageInfo.pages}"></span> 页,共 <span th:text="${pageInfo.total}"></span> 条记录</p></th>
<th width="10%"><a style="color: blue" th:href="@{/providers}">首页</a></th>
<th width="10%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></th>
<th width="10%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></th>
<th width="30%"><a style="color: blue" th:href="@{/providers(pageNum=${pageInfo.pages})}">尾页</a></th>
</tr> </table>
5.配置好以上文件就能进行测试了
测试结束,OK
spring_boot 中通过PageHelper分页的更多相关文章
- 17-SSM中通过pagehelper分页的实现
SSM中通过pagehelper分页的实现 1. 在SSM框架的基础上实现,导包 <!-- 分页 --> <dependency> <groupId>com.git ...
- 如何在实际项目中使用PageHelper分页插件
PageHelper是一个分页插件,能够简单快速的帮助开发人员完成常见的分页功能,你只需要简单的使用两行代码就可以完成一个分页效果- 最近做一个科创项目,使用Maven+SSM的环境,有分页的功能,于 ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- PageHelper分页插件的使用
大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...
- spring-boot-2.0.3源码篇 - 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.获取分 ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
随机推荐
- 为什么SSL证书要设有效期?
1.首先是为了安全考虑,CA机构不能保证一个网站永远是合法的,因此它需要定期检查网站. 2.其次,以往CA证书都非常贵,签发证书的机构通过设置期限来收费,是一种商业途径. 3.最后,还有最重要的原因就 ...
- Win10安装7 —— 系统的优化
本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/xuexianqi/p/12371356.html 一:引言 在我们使用电脑的过程中,总是有一些窗口弹出来需 ...
- 将Python模块转变为命令行工具
问:如何输入命令行就能执行python代码呢? 答:要将python模块转变为命令行工具只用在 setup.py 文件中添加参数entry_points 例如: entry_points={ 'con ...
- java编码解码过程
最近做项目的时候,有时会遇到中文乱码的问题,网上查询了很多资料,发现大多都是只讲解决方案,并没有讲到为什么要使用这种方案,这种方案的原理是什么? 最典型的就是连接数据库的URL,我们一般把它放到cla ...
- Wannafly Camp 2020 Day 1H 最大公约数 - 质因数分解,高精度
把每个质因子扒出来乱搞一下 #include <bits/stdc++.h> using namespace std; int g[505][505]; int isp[505]; str ...
- SpringMVC进行Ajax请求页面显示乱码
最近在项目的使用过程中发现在springmvc的项目中,使用返回页面的请求方式,数据都能正常显示,但是对于ajax的请求,始终显示乱码. 首先第一种是因为我们在web.xml中配置了spring的字符 ...
- codeforces 1285D. Dr. Evil Underscores(字典树)
链接:https://codeforces.com/problemset/problem/1285/D 题意:给n个数a1,a2,a3.....an,找到一个数X,使得X 异或所有的ai ,得到的ma ...
- 剑指offer 面试题43. 1~n整数中1出现的次数
leetcode上也见过一样的题,当时不会做 看了一下解法是纯数学解法就没看,结果剑指offer上也出现了这道题,那还是认真看下吧 对于数字abcde,如果第一位是1,比如12345,即计算f(123 ...
- 【STM32H7教程】第59章 STM32H7的DAC基础知识和HAL库API
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第59章 STM32H7的DAC基础知识和HAL库 ...
- Unity3d简便的声音管理方案
本方法是对Ez-Sound-Manager的扩展 https://github.com/JackM36/Eazy-Sound-Manager 参考Audio Toolkit Free Version ...