Spring Boot实践——Mybatis分页插件PageHelper的使用
出自:https://blog.csdn.net/csdn_huzeliang/article/details/79350425
在springboot中使用PageHelper插件有两种较为相似的方式,接下来我就将这两种方式进行总结。
- 方式一:使用原生的PageHelper
1.在pom.xml中引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.3</version>
</dependency>
2.在springboot的启动类(Application.java)里面注入配置
@Bean
PageHelper pageHelper(){
//分页插件
PageHelper pageHelper = new PageHelper();
Properties properties = new Properties();
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("returnPageInfo", "check");
properties.setProperty("params", "count=countSql");
pageHelper.setProperties(properties); //添加插件
new SqlSessionFactoryBean().setPlugins(new Interceptor[]{pageHelper});
return pageHelper;
}
- 方式二:使用PageHelper的starter
1.在pom.xml中引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
2.在application.properties配置pagehelper的属性
#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
最后就是使用pagehelper进行分页了,其中最重要的一句就是
PageHelper.startPage(pageNum,pageSize);pageNum:当前页数 pageSize:当前页需要显示的数量
例如:
public PageInfo<Blog> ajaxBlog(Integer pageNum,Integer pageSize){
PageHelper.startPage(pageNum,pageSize);
List<Blog> blogList = blogMapper.selectByExample(new BlogExample());
PageInfo<Blog> pageInfo = new PageInfo<Blog>(blogList);
return pageInfo;
}
Spring Boot实践——Mybatis分页插件PageHelper的使用的更多相关文章
- spring boot集成mybatis分页插件
mybatis的分页插件能省事,本章记录的是 spring boot整合mybatis分页插件. 1.引入依赖 <!-- 分页插件pagehelper --> <dependency ...
- boot集成mybatis分页插件pagehelper
导入依赖 <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter ...
- spring boot集成mybatis(2) - 使用pagehelper实现分页
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- Mybatis分页插件PageHelper的配置和使用方法
Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...
- Mybatis学习---Mybatis分页插件 - PageHelper
1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...
- Mybatis分页插件-PageHelper的使用
转载:http://blog.csdn.net/u012728960/article/details/50791343 Mybatis分页插件-PageHelper的使用 怎样配置mybatis这里就 ...
- (转)淘淘商城系列——MyBatis分页插件(PageHelper)的使用以及商品列表展示
http://blog.csdn.net/yerenyuan_pku/article/details/72774381 上文我们实现了展示后台页面的功能,而本文我们实现的主要功能是展示商品列表,大家要 ...
- MyBatis 分页插件PageHelper 后台报错
今天遇到一个问题,使用MyBatis 分页插件PageHelper 进行排序分页后,能正常返回正确的结果,但后台却一直在报错 net.sf.jsqlparser.parser.ParseExcepti ...
- Mybatis分页插件PageHelper使用
一. Mybatis分页插件PageHelper使用 1.不使用插件如何分页: 使用mybatis实现: 1)接口: List<Student> selectStudent(Map< ...
随机推荐
- Git Authoritative Guide 学习
一.git命令1.git add -u : 将工作区中所有改动的文件添加到暂存区(修改.删除),但是不提交未被git跟踪的文件 -i : 可以进入交互界面选择性提交 -A : 相对于-u,它还提交新建 ...
- ZH奶酪:Python使用ElementTree解析XML【译】
19.7. xml.etree.ElementTree — The ElementTree XML API 源代码: Lib/xml/etree/ElementTree.py Element类型是一种 ...
- apache flink kubernetes 运行试用
类似docker-compose 运行模式,使用的是deploy 的模式 deploy yaml 文件 deploy-k8s-yaml apiVersion: extensions/v1beta1 k ...
- vertx.io 与nodejs 一个简单的性能比较
vertx.io 与node 都是可以进行js运行的一个引擎,但是vertx 支持的语言相对于node 多,可以查看官网.今天下网上查询相关的信息 时来了解到vertx.io 性能比node 好,于是 ...
- Spring插件3.8.2的安装
主机环境:win8 64bit eclipse版本:4.5.2 MARS 插件版本:Spring Tool Suite3.8.2 安装过程:直接在线安装,没有先在官网把插件下载再安装. 主要步骤: 1 ...
- 网络基础 TCP/IP
为了理解 HTTP,我们有必要事先了解一下 TCP/IP 协议族.通常使用的网络(包括互联网)是在 TCP/IP 协议族的基础上运作的.而 HTTP 属于它内部的一个子集.接下来,我们仅介绍理解 HT ...
- k最邻近算法——使用kNN进行手写识别
上篇文章中提到了使用pillow对手写文字进行预处理,本文介绍如何使用kNN算法对文字进行识别. 基本概念 k最邻近算法(k-Nearest Neighbor, KNN),是机器学习分类算法中最简单的 ...
- linq to sql (Group By/Having/Count/Sum/Min/Max/Avg操作符) (转帖)
http://wenku.baidu.com/link?url=2RsCun4Mum1SLbh-LHYZpTmGFMiEukrWAoJGKGpkiHKHeafJcx2y-HVttNMb1BqJpNdw ...
- sql having 函数 按匿名字段作为条件进行查询
今天写sql 遇到一个问题 SELECT a.*, count(b.id) AS nums FROM a LEFT JOIN b ON a.id=b.a_id WHERE nums>1 这时候会 ...
- 【Spring学习笔记-MVC-14】Spring MVC对静态资源的访问
作者:ssslinppp 参考链接: http://www.cnblogs.com/luxh/archive/2013/03/14/2959207.html http://www.cnb ...