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 ...
随机推荐
- 微信自带浏览器不支持form表单post提交方案解决
微信自带浏览器form表单post提交,Java控制后台获取不到值得解决方案: 第一种:把post改成get请求,但是改后另一个问题来了就是,数据不安全了,连接上都能看到,导致数据会流失,Java ...
- 排序算法(Gif动图演示)
冒牌排序(BubbleSort) 冒泡排序是一种比较简单的排序算法,它循环走过需要排序的元素,依次比较相邻的两个元素,如果顺序错误就交换,直至没有元素交换,完成排序. 若对n个人进行排序,我们需要n- ...
- WebApp与Native App有何区别呢?
Native App(其实就是用java其他语言开发的安卓系统或ios系统): 1.开发成本非常大. 一般使用的开发语言为JAVA.C++.Objective-C. 2 ...
- python待学习内容
1.Python中不尽如人意的断言Assertion https://www.cnblogs.com/cicaday/p/python-assert.html 2.Python中的反转字符串问题 ht ...
- Jmeter+badboy压力测试总结
流程:badboy导出Jmeter压测脚本 -> Jmeter进行压力测试 软件下载地址: badboy:http://www.badboy.com.au/ Jmeter:http://jmet ...
- 链接错误:multiple definition of 'xxx' 问题解决及其原理
内容借鉴 于CSDN炸鸡叔 错因 截图: “multiple definition of 'head' ” “multiple definition of 'tail' ” 解决过程: 1.首先要 ...
- Python学习—框架篇之初识Django
什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. 对于所有的W ...
- java基础 ----- 程序的调试
--- -- 什么是程序调试 当程序出错时,我们希望可以这样 逐条语句执行程序 ----- 观察程序的执行情况 ------ 发现问题 ----- 解决问题 但是,程序一闪就运行结束 ...
- 浅谈spring为什么推荐使用构造器注入
转载自: https://www.cnblogs.com/joemsu/p/7688307.html 一.前言 Spring框架对Java开发的重要性不言而喻,其核心特性就是IOC(Inversi ...
- jq实现前端文件上传
FormData FormData是XMLHttpRequest Level 2 新增的一个接口. 使用FormData可以实现各种文件上传. 使用 // 创建FormData的实例 var form ...