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);