解决: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)]

解决方法

手动添加依赖

不用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 {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    @Bean
    ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return new ConfigurationCustomizer() {
            @Override
            public void customize(MybatisConfiguration configuration) {
                configuration.addInterceptor(new com.github.pagehelper.PageInterceptor());
            }
        };
    }
}

测试一下

    @Test
    public 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);
    }
  • 16
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值