分页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. linux--vsftpd的安装和配置(转)

    Linux下如何进行FTP设置(转) [TOC] Redhat/CentOS安装vsftp软件 1. 安装vsftp $ yum install vsftpd -y 2. 添加ftp帐号和目录 先检查 ...

  2. Android Studio 1.5.1

    Android Studio 1.5.1 December 3rd, 2015: For information on what's new in 1.5.1, see the release ann ...

  3. HTTP node静态资源请求加载demo

    MIME type的缩写为(Multipurpose Internet Mail Extensions)代表互联网媒体类型(Internet media type),MIME使用一个简单的字符串组成, ...

  4. gitbucket

    github固然强大,但不怎么适合企业级的开发版本管理,原因相信大家都明白,首先在github上上传和拉取代码速度是比较慢的,再者,在Github上创建一个私有仓库是收费的,那么gitbucket是一 ...

  5. 洛谷 - P2730 - 魔板 Magic Squares - bfs

    写状态转移弄了很久,老了,不记得自己的数组是怎么标号的了. #include <bits/stdc++.h> using namespace std; #define ll long lo ...

  6. 洛谷 - P1355 - 神秘大三角 - 简单计算几何

    https://www.luogu.org/problemnew/show/P1355 判断一个点和三角形的位置关系,最简单的思路就是用向量. 首先排除掉和三角形顶点重合的情况. 把三角形设计成一个首 ...

  7. SpringBoot自定义参数解析器

    一.背景 平常经常用 @RequestParam注解来获取参数,然后想到我能不能写个自己注解获取请求的ip地址呢?就像这样 @IP String ip 二.分析 于是开始分析 @RequestPara ...

  8. UWP 动画

    一:StoryBoard 一般翻译成演示图版或者故事板,就像电影中的情节串联板,它是一个动画时间线的容器. 二:动画的分类       简单动画:以Animation结尾,例如DoubleAnimat ...

  9. [洛谷P2417]课程

    题目链接: 点我 题目分析: 二分图最大匹配裸题,跑完匈牙利判断\(ans\)是否等于教室数即可 多组数据请注意初始化. 代码: #include<bits/stdc++.h> #defi ...

  10. 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

    题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...