分页jar包:

<dependency>
  <groupId>com.github.pagehelper</groupId>
  <artifactId>pagehelper</artifactId>
  <version>5.1.1</version>
</dependency>

配置:

import java.util.Properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.github.pagehelper.PageInterceptor;

@Configuration
public class PageHelperConfig {

@Value("${pagehelper.helperDialect}")
private String helperDialect;

@Bean
public PageInterceptor pageInterceptor() {
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
properties.setProperty("helperDialect", helperDialect);
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
}

package test.test.config;

import javax.sql.DataSource;

import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement; import com.github.pagehelper.PageInterceptor; @Configuration
@MapperScan("com.xx.dao")
@EnableTransactionManagement
public class DataSourceConfig { @Autowired
private Environment env; @Autowired
private PageInterceptor PageInterceptor; @Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
fb.setDataSource(dataSource);
// 该配置非常重要,如果不将PageInterceptor 设置到SqlSessionFfactory中,导致分页失效
fb.setPlugins(new Interceptor[] {PageInterceptor});
fb.setTypeAliasesPackage(env.getProperty("mybaertis.type-aliases-package"));
fb.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(env.getProperty("mybatis.mapper.locations")));
return fb.getObject();
} @Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
DataSourceTransactionManager dataSourceTransactionManager =
new DataSourceTransactionManager();
dataSourceTransactionManager.setDataSource(dataSource);
return dataSourceTransactionManager;
} }

配置文件配置

pagehelper.helperDialect = oracle
pagehelper.reasonable = true
pagehelper.supportMethodsArguments = true
pagehelper.params = count=countSql
pagehelper.returnPageInfo = check

使用:
@RequestParam(name="pageNum",required =false,defaultValue="1") int pageNum,
@RequestParam(name="pageSize",required =false,defaultValue="1") int pageSize

PageHelper.startPage( pageNum,pageSize);

pagehelper 分页的更多相关文章

  1. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  2. PageHelper分页插件的使用

    大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...

  3. SpringBoot整合系列-PageHelper分页插件

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...

  4. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  5. 记录pageHelper分页orderby的坑

    pageHelper的count查询会过滤查询sql中的order by条件! pageHelper分页功能很强大,如果开启count统计方法,在你执行查询条件时会再执行一条selet count(* ...

  6. mybatis pagehelper分页插件使用

    使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...

  7. spring boot 整合pagehelper分页插件

    Spring Boot 整合pagehelper分页插件 测试环境: spring boot  版本 2.0.0.M7 mybatis starter 版本  1.3.1 jdk 1.8 ------ ...

  8. pageHelper分页

    引入jar包 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pag ...

  9. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  10. 求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

    存储过程如下: dao层的sql Controller层调用: html页面 没有使用pagehelper分页之前,可以正常使用 使用了pagehelper之后就报错 ### Error queryi ...

随机推荐

  1. Ordered Fractions

    链接 分析:遍历一下,求个gcd即可,最后按照ans排序并去重 /* PROB:frac1 ID:wanghan LANG:C++ */ #include "iostream" # ...

  2. 【旧文章搬运】Windbg+Vmware驱动调试入门(四)---VirtualKD内核调试加速工具

    原文发表于百度空间,2009-01-09========================================================================== 今天又想起 ...

  3. 【旧文章搬运】Windbg+Vmware驱动调试入门(二)---Vmware及GuestOS的设置

    原文发表于百度空间,2009-01-08========================================================================== 这一篇是主 ...

  4. C++ 多项目dll调用-隐式

    将DAA人脸检测做成动态库以便其他程序调用,采用隐式调用完成. 给出部分关于dll制作的关键代码: 1.DLL 多项目DLL编写注意将其他相关项目设置成静态库,以及各库涉及的版本一致性. DLL.h ...

  5. 常用js方法集合

    var func={ //对象转jsonstring getJsonStr: function(jsonObj) { var temp = []; for (var key in jsonObj) { ...

  6. HDOJ5020【几何】

    题意: 给你n个点,问有几对三个点在一条直线上 思路: 目前为止很少写的几何题- 一开始两层for没有判断重复. 然后看了一些题解说排序一下,然后枚举每个点,求一个同一斜率的个数k,ans+=(k-1 ...

  7. bzoj 5498: [2019省队联测]皮配【dp】

    是个神仙dp-- 参考:https://www.luogu.org/blog/xzz-233/solution-p5289 设f[i][j][k]是前i个有限制的城市,所有学校中选蓝色阵营有j人,有限 ...

  8. CF788B Weird journey

    总共有n个节点,m条路径,要求其中m-2条路径走两遍,剩下2条路径仅走一遍,问不同的路径总数有多少,如果仅走一遍的两条边不同则将这两条路径视为不同. 可以把每条边都拆成两条重边,每条边的度数都是偶数了 ...

  9. mysql 分区后查询效率

    准备工作: 蠕虫复制 文章表 增加数据到112万 语法:insert into  tableNameA  select * from tableNameB       未分区查询  54s 改变现有表 ...

  10. 分析spring aop的源码实现

    AOP就是面向切面编程,我们可以从几个层面来实现AOP. 在编译器修改源代码,在运行期字节码加载前修改字节码或字节码加载后动态创建代理类的字节码,以下是各种实现机制的比较. spring AOP是Sp ...