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. git配置多仓库

    git配置多仓库 github , gitee , coding , gitlab , gitlab.company ..... 真TM多 . 真TM多 . 真TM多 . 生成ssh 生成ssh 密钥 ...

  2. JAVA StringUtils工具类

    org.apache.commons.lang Class StringUtils java.lang.Object org.apache.commons.lang.StringUtils publi ...

  3. cssflex兼容(横向顶边对齐)

    display: flex; display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; ...

  4. python package install error and little code bugs

    When you install packages using setup.py, the error: (py37) C:\Users\weda\Phd\python packages\visibi ...

  5. 【转】Java Future 怎么用 才算是真正异步

    接着上一篇继续并发包的学习,本篇说明的是Callable和Future,它俩很有意思的,一个产生结果,一个拿到结果.        Callable接口类似于Runnable,从名字就可以看出来了,但 ...

  6. 重新认识urllib

    # coding=utf-8 # urllib_get_file=urllib.request.urlretrieve(url=None,filename="test.zip") ...

  7. redis相关问题记录

    问题:无法在redis自行set操作 错误信息:(error) MISCONF Redis is configured to save RDB snapshots, but is currently ...

  8. C语言sprintf函数的深入理解

    由于sprintf跟printf在用法上几乎一样,只是打印的目的地不同而已,前者打印到字符串中,后者则直接在命令行上输出.这也导致sprintf比printf有用得多.所以本文着重介绍sprintf, ...

  9. JavaScript的Map和Set

    JavaScript的Map和Set 1.map:映射(通过key获得value).增.删 2.set:增.删.判断是否包含某个元素 1. Map <!DOCTYPE html><h ...

  10. jQuery jqgrid

    1.写div <div class="ibox-content"> <div class="jqGrid_wrapper"> <! ...