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%">&nbsp;------=--</th>
<th width="20%">&nbsp;----=-----</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分页的更多相关文章

  1. 17-SSM中通过pagehelper分页的实现

    SSM中通过pagehelper分页的实现 1. 在SSM框架的基础上实现,导包 <!-- 分页 --> <dependency> <groupId>com.git ...

  2. 如何在实际项目中使用PageHelper分页插件

    PageHelper是一个分页插件,能够简单快速的帮助开发人员完成常见的分页功能,你只需要简单的使用两行代码就可以完成一个分页效果- 最近做一个科创项目,使用Maven+SSM的环境,有分页的功能,于 ...

  3. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  4. PageHelper分页插件的使用

    大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...

  5. spring-boot-2.0.3源码篇 - pageHelper分页,绝对有值得你看的地方

    前言 开心一刻 说实话,作为一个宅男,每次被淘宝上的雄性店主追着喊亲,亲,亲,这感觉真是恶心透顶,好像被强吻一样.........更烦的是我每次为了省钱,还得用个女号,跟那些店主说:“哥哥包邮嘛么叽. ...

  6. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  7. 记录pageHelper分页orderby的坑

    pageHelper的count查询会过滤查询sql中的order by条件! pageHelper分页功能很强大,如果开启count统计方法,在你执行查询条件时会再执行一条selet count(* ...

  8. mybatis pagehelper分页插件使用

    使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...

  9. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

随机推荐

  1. ECMAScript基本语法——⑤运算符 void

    void阻止返回值的运算符,没有返回值

  2. 获取url参数(jq 扩展包)

    (function($){ $.extend({ urlGet:function(url) { var getUrl = url ? url.split("?") : window ...

  3. 0005 uwsgi配置

    在配置文件目录Configurations下创建一个名为uwsgi.ini的文件,用于uwsgi服务配置. uwsgi在服务器上使用,接收nginx的转发请求. 内容如下: # 配置文件:这一行必须有 ...

  4. 安装python3.7.4时报错:Service Pack 1 is required to continue installation

    python3.7.4安装失败:Service Pack 1 is required to continue installation 解决办法: 点击报错页面中的“log file”,日志最后一行显 ...

  5. javaScript(Date与Math的API)

    目录 Math Math的两个属性值 E PI abs(); ceil(); floor(); round(); max(); min (); pow(); random sin(); cos(); ...

  6. AE 打开Shp文件

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. 【C/C++】最短路径

    BFS求无权图的最短路径 用book数组的值表示路径长度即可,省略 Floyd算法(允许负边) Floyd算法可以一次性求出所有节点之间的最短距离,且代码简单,但是时间复杂度达到了n^3,因此只适用于 ...

  8. jQuery---版本问题

    jQuery的版本 官网下载地址:http://jquery.com/download/ jQuery版本有很多,分为1.x 2.x 3.x 大版本分类: 1.x版本:能够兼容IE678浏览器 2.x ...

  9. SequoiaDB 巨杉数据库Docker镜像使用教程

    为方便用户快速体验,SequoiaDB 巨杉数据库提供基于 Docker 的镜像.本文介绍如何在 Docker 环境下部署 SequoiaDB 分布式集群环境.   集群规划 我们准备在五个容器中部署 ...

  10. mysql-sql分析策略及优化

    tranlation事务:从失败中回复到正常状态的方法多个应用并发访问数据库时,提供隔离方法 acid原子性:要么成功.要么失败一致性:数据保持“合理性”隔离型:多个事务同时并发执行,每个事务就像各自 ...