1.pom中引入PageHelper插件的依赖。这里引入的不是单独的PageHelper包,而是整合到springboot后的,由于冗余了mybatis-spring-boot-starter
,在项目中如果没有引入mybatis的依赖。这里不用剔除掉。如果上面的pom中引入过,则这里要剔除掉。
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
这里首先要知道PageHelper支持那些库的分页查询。可以看源码的类了解一下。
这里默认支持的有Db2,Hsql,Informix,MySql,Oracle,SqlServer常用数据库都包含在内。所以在整合springboot时,需要通过
设置断言来指定用的是啥数据库来执行分页。这里有两种方式:
第一种:在启动类Application.java中初始化指定.这种我不推荐用,而推荐第二种配置方式。
//配置mybatis的分页插件pageHelper
2 @Bean
3 public PageHelper pageHelper(){
4 PageHelper pageHelper = new PageHelper();
5 Properties properties = new Properties();
6 properties.setProperty("offsetAsPageNum","true");
7 properties.setProperty("rowB