本文主要是介绍解决:java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.Plain【Mybatis3.x + PageHelper】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在使用mybatis-plus3.x+pagehelper作为分页方案的时候,使用如下:
<!--1.2.3版本--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId></dependency><!--mybatis-plus--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.1</version></dependency>
报如下错误:
java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.Plain
查找资料之后,发现是jsqlparser的版本不对导致的。
pagehelper-sprng-boot-starter 使用的是的版本是1.0版本,说是版本太低。
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DBvlp27C-1610690829119)(C:\Users\huayuhao\AppData\Roaming\Typora\typora-user-images\image-20210115111743736.png)]](https://img-blog.csdnimg.cn/202101151407295.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1NreV9RaWFvQmFfU3Vt,size_16,color_FFFFFF,t_70)
解决方法
手动添加依赖
不用pagehelper-sprng-boot-starter ,手动添加依赖。
<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><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId></dependency>
手动添加拦截器
@Configuration
public class MpConfig {@Beanpublic PaginationInterceptor paginationInterceptor() {return new PaginationInterceptor();}@BeanConfigurationCustomizer mybatisConfigurationCustomizer() {return new ConfigurationCustomizer() {@Overridepublic void customize(MybatisConfiguration configuration) {configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());}};}
}
测试一下
@Testpublic void testPageHelper() {PageHelper.startPage(1, 2);List<DomainVo> domainVos = mapper.selectList(null).stream().map(this::convertEntity2Vo).collect(Collectors.toList());PageInfo<DomainVo> pageInfo = new PageInfo<>(domainVos);System.out.println(pageInfo);}
这篇关于解决:java.lang.NoSuchMethodError: net.sf.jsqlparser.statement.select.Plain【Mybatis3.x + PageHelper】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!