pagehelper 分页
分页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 分页的更多相关文章
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- PageHelper分页插件的使用
大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...
- SpringBoot整合系列-PageHelper分页插件
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分页插件PageHelper ...
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- 记录pageHelper分页orderby的坑
pageHelper的count查询会过滤查询sql中的order by条件! pageHelper分页功能很强大,如果开启count统计方法,在你执行查询条件时会再执行一条selet count(* ...
- mybatis pagehelper分页插件使用
使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...
- spring boot 整合pagehelper分页插件
Spring Boot 整合pagehelper分页插件 测试环境: spring boot 版本 2.0.0.M7 mybatis starter 版本 1.3.1 jdk 1.8 ------ ...
- pageHelper分页
引入jar包 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pag ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- 求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
存储过程如下: dao层的sql Controller层调用: html页面 没有使用pagehelper分页之前,可以正常使用 使用了pagehelper之后就报错 ### Error queryi ...
随机推荐
- iOS 开发图片资源选择png格式还是jpg格式
对于iOS本地应用程序来说最简单的答案就是始终使用PNG,除非你有非常非常好的理由不用它. 当iOS应用构建的时候,Xcode会通过一种方式优化.png文件而不会优化其它文件格式.它优化得相当的好 他 ...
- Codechef SEPT17
Codechef SEPT17 比赛链接:https://www.codechef.com/SEPT17 CHEFSUM code给定数组 a[1..n] ,求最小的下标 i ,使得 prefixsu ...
- kubernetes1.13.1部署ingress-nginx-十一
一.Ingress 简介 (1) 在Kubernetes中,服务和Pod的IP地址仅可以在集群网络内部使用,对于集群外的应用是不可见的. 为了使外部的应用能够访问集群内的服务, 在Kubernetes ...
- DPWL具关劳过农派广决建
圆来压平便几从细样听二现当群世权半几影志土济长即江装家革候它准原打边社而从越何从式万难因造化阶求电么才论须指直很已毛有济做把活半或须白安共角争斗也重代只因识九少�
- sql server通过脚本进行数据库压缩全备份的方法
问题:生产环境的数据库可能比较大,如果直接进行全备而不压缩的话,备份集就会占用了大量磁盘空间.给备份文件的存放管理带来不便. 解决方案:通过with compression显式启用备份压缩,指定对此备 ...
- python __builtins__ 函数
dir(__builtins__) 1.'abs', 对传入参数取绝对值 abs(x, /) Return the absolute value of the argument. >>&g ...
- bzoj 4753: [Jsoi2016]最佳团体【01分数规划+二分+树上背包】
01分数规划,二分答案然后把判别式变成Σp[i]-Σs[i]*mid>=0,然后树上背包判断,设f[i][j]为在i点子树里选j个的最大收益,随便背包一下就好 最丧病的是神卡常--转移的时候要另 ...
- P1648 看守
传送门 以二维的两个点\((x1,y1),(x2,y2)\)为例,那么他们之间的曼哈顿距离肯定为一下四个之一\((x1-x2)+(y1-y2)\),\((x2-x1)+(y1-y2)\),\((x1- ...
- 公司内网,无法使用yum在线下载,肿么办?
1 配置上网代理 编辑/etc/yum.conf,增加如下属性: proxy=你的代理地址 proxy_user=你的用户名 proxy_password=你的密码 2 配置国内163 yum源 备份 ...
- rabbitMQ的使用
介绍 一款消息队列数据库,类似redis发布订阅,但是rq 做了功能完善和数据持久化.在项目中,将一些无需即时返回且耗时的操作提取出来,进行了异步处理,而这种异步处理的方式大大的节省了服务器的请求响应 ...