SpringBoot整合mybatis结合pageHelper插件实现分页
SpringBoot整合mybatis分页操作
SpringBoot整合Mybatis进行分页操作,这里需要使用Mybatis的分页插件:pageHelper,
关于pageHelper的介绍,请查看官方文档:https://pagehelper.github.io/
1、使用前配置
关于pageHelper的使用配置,主要有以下2个步骤:
1.1、在pom文件中导入pageHelper依赖
com.github.pagehelper pagehelper-spring-boot-starter 1.2.12
说明:
这里使用的pageHelper依赖只做演示,需要使用最新的pageHelper依赖可以去maven中央仓库下载,
中央仓库地址:https://mvnrepository.com/
1.2、在application.yml文件中配置PageHelper插件
#pageHelper分页配置 pagehelper: helper-dialect:mysql reasonable:true support-methods-arguments:true params:count=countSql
2、使用pageHelper插件
由于pageHelper插件内置了分页PageBean对象:PageInfo,所以,这里使用主要有以下几个步骤:
1>在service层进行分页
2>设置分页参数:PageHelper.startPage(page,size),其中page为当前页,size为每页显示条数
3>调用dao层的查询全部方法:PageHelper插件会自动的对下边第一个查询方法进行分页
4>封装返回值PageInfo
publicPageInfofindByPageHelper(intpage,intsize){ //1、调用PageHelper的startPage方法设置参数 PageHelper.startPage(page,size); //2、调用查询全部的方法 Listlist=companyDao.selectList(null); //3、构造pageInfo返回值 returnnewPageInfo(list); }
到此这篇关于SpringBoot整合mybatis使用pageHelper插件进行分页操作的文章就介绍到这了,更多相关SpringBoot整合mybatis进行分页操作内容请搜素毛票票以前的文章或下面相关文章,希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。