jeecgboot 自帶的分頁插件使用非常方便,但是無法解決自定義 sql 的問題;一般的 springboot 工程使用 pagehelper 分頁插件都是通過 pom.xml 引入 pagehelper-spring-boot-starter 依賴 + application.properties 配置 pagehelper相關配置的方式,但是在 jeecgboot 工程中 pagehelper-spring-boot-starter 和 mybatis-plus-spring-boot-starter 同時引入啓動時會報錯,所以可以採用不使用 pagehelper-starter ,直接使用 pagehelper + 手動添加 pagehelper mybatis 攔截器的方式:
即 pom.xml 中:
<!--pagehelper 分頁插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
<!--pagehelper 內部依賴的 -->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>2.1</version>
</dependency>
MybatisPlusConfig 中:
@Bean
ConfigurationCustomizer mybatisConfigurationCustomizer() {
return new ConfigurationCustomizer() {
@Override
public void customize(MybatisConfiguration configuration) {
configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
}
};
}
使用:
PageHelper.startPage( pageNo,pageSize );
List<ProInfo> proInfoList = this.proInfoMapper.queryList( l );
PageInfo<ProInfo> proInfoPageInfo = new PageInfo<>(proInfoList);