SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
**SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了。全部自动实现。
话不多说,直接上代码:
第一步pom文件配置添加jar:###
<!-- mybatis的分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
第二步配置application.properties文件或者 application.yml 文件:###
注意你是配置的什么数据进行分页操作 pagehelper.helperDialect=postgresql 我这里是postgresql数据库
支持Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库
application.properties:###
#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
application.yml
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
第三步配置运行类 Application 添加pagehelp插件,在main方法之后被加载###
@SpringBootApplication
//将项目中对应的mapper类的路径加进来就可以了
@MapperScan({"org.baihuida.hints.dao"})
public class CodeHintsApplication {
public static void main(String[] args) {
SpringApplication.run(CodeHintsApplication.class, args);
}
//配置mybatis的分页插件pageHelper
@Bean
public PageHelper pageHelper(){
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("offsetAsPageNum","true");
properties.setProperty("rowBoundsWithCount","true");
properties.setProperty("reasonable","true");
properties.setProperty("dialect","mysql"); //配置mysql数据库的方言
pageHelper.setProperties(properties);
return pageHelper;
}
}
第四步配置controller层:
@RequestMapping("queryKeywords")
public PageInfo<Keywords> queryKeywords(@RequestParam(defaultValue="1") int pageNum,
@RequestParam(defaultValue="3") int pageSize) {
PageInfo<Keywords> pageInfo = keywordsService.getLogInfoPage(pageNum,pageSize);
return pageInfo;
}
第五步配置service层:
@Override
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Keywords> list= keywordsMapper.listKeywords();
PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
return pageInfo;
}
第六步配置 service
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize);
实现类
@Override
public PageInfo<Keywords> getLogInfoPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum,pageSize);
List<Keywords> list= keywordsMapper.listKeywords();
PageInfo<Keywords> pageInfo = new PageInfo<Keywords>(list);
return pageInfo;
}
第七步Dao层:
List<Keywords> listKeywords();
第八步xml层:
<select id="listKeywords" resultType="org.baihuida.hints.entity.Keywords">
select keyword from keywords
</select>
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页的更多相关文章
- Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板
作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程
Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
- 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...
- SpringBoot整合系列-PageHelper分页插件
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...
- 后端——框架——持久层框架——Mybatis——补充——pageHelper(分页)插件
Pagehelper插件的知识点大致可以分为三个部分 搭建环境,引入jar包,配置. 使用方式,只需要记住一种即可.类似于在写SQL语句中,可以left join,也可以right join,它们实现 ...
- springboot+mybatis使用PageHelper分页
项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...
随机推荐
- js 监听手机端键盘弹出和收起事件
//这里区分不同系统,可以参考之前的文档记录 https://www.cnblogs.com/wind-wang/p/10737110.html const ua = typeof window == ...
- NTP时间服务
时间服务 NTP:Network Time Protocol 作用:用来给其他主机提供时间同步服务 NTP的配置文件 /etc/ntp.conf NTP相关的命令 date:显示/修改系统时间 hwc ...
- Spring再接触 Annotation part2
resource resource beans.xml <?xml version="1.0" encoding="UTF-8"?> <bea ...
- ArcGIS案例教程-通过点坐标生成圆
ArcGIS案例教程-通过点坐标生成圆 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 功能:以点坐标为中心,通过指定半径,生成圆 成果形式:绿色工具,免安装,不限版 ...
- CentOS6.3上搭建expect无交互开发环境
1.背景 在面向shell编程时对于需要交互的场合则必须通过人工来干预,而对于这种方式是违反无人职守的原则:现在expect就解决了这个问题, Expect是一个免费的编程工具语言,用来实现自动和交互 ...
- elasticsearch批量修改,批量更新某个字段
1.源生API 在这里没有用官方提供的bulk API,而是用的另外一种方式. POST /infomations/infomations/_update_by_query JSON请求格式 { &q ...
- linux查看进程已经运行了多长时间
ps -eo lstart 启动时间 ps -eo etime 运行多长时间. ps -eo pid,lstart,etime | grep 717
- XACT_ABORT选项
XACT_ABORT选项用于指定当SQL语句出现运行时错误时,SQL Server是否自动回滚到当前事务.其语法格式如下所示: SET XACT_ABORT{ON|OFF} 当SET XACT_ABO ...
- Java8-函数式接口理解及测试
1. 函数式接口的理解 根据重构的思想,需要把容易变化的模块进行抽象并封装起来,从这个点来看,Java8新引入的函数式接口就是基于这个思想进行设计的. 2. 函数式接口定义 2.1 自定义如下 需要 ...
- 【codelife 阿里技术文章分享——读后感】
目前看到的几篇比较有感触的文章,分别是: 前端Leader如何做好团队规划?阿里内部培训总结公开 ——>这里会有关于针对技术项目如何做规划的一些指导,非常有价值 程序员吃的是青春饭?本质上取 ...