1.背景:
以前一直用的mybatis,用pagehelper做分页,后来引用了mybatis-plus,以前pagehelper做的分页突然就都报错了。
java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.PlainSelect.getGroupByColumnReferences()Ljava/util/List;
以前引用
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.2.0</version>
</dependency>
2.查看引用的包发现:
pagehelper5.1.8里面用的jsqlparser用的版本为1.2
而mybatis-plus-core 3.2.0里面用的jsqlparser版本是2.1
只有低版本的jsqlparser里面才有getGroupByColumnReferences这个方法
jsqlparser版本不一致,发现pagehelper5.1.10用的jsqlparser版本为2.0,将pagehelper版本升级
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.2.0</version>
</dependency>
经测试,使用的pagehelper没有报错,但是可能分页无效
将mybatisConfig.xml中配置如下即可正常使用
<plugins>
<!--mybatisplus分页配置-->
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor">
</plugin>
<!--pagehelper分页配置-->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>