springboot-mybatis-plus-starter和springboot-pagehelper-starter不兼容报错解决

案发现场:

在这里插入图片描述
原因是这两个库用的jsqlparser版本不一致导致的

解决方案

先把jsqlparser都排除掉 然后单独引入jsqlparser依赖:

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.5</version>
    <exclusions>
        <exclusion>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>2.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>com.github.jsqlparser</groupId>
            <artifactId>jsqlparser</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>sqlparser4.5</artifactId>
    <version>6.1.0</version>
</dependency>

然后创建一个类修改方言解析器即可:
LocalMySqlDialect.java

import com.github.pagehelper.dialect.helper.MySqlDialect;
import com.github.pagehelper.parser.CountSqlParser;
import com.github.pagehelper.parser.OrderBySqlParser;
import com.github.pagehelper.parser.OrderByJSqlParser45;
import com.github.pagehelper.parser.CountJSqlParser45;
import com.github.pagehelper.util.ClassUtil;

import java.util.Properties;

/**
 * PageAutoDialect这个类是用来管理注册方言的,它在MySql的方言中默认使用了com.github.pagehelper.dialect.helper.MySqlDialect类,
 * 而MySqlDialect类继承自com.github.pagehelper.dialect.AbstractDialect类,而AbstractDialect默认实现了setProperties方法,不兼容的地方就在这里
 */
public class LocalMySqlDialect extends MySqlDialect {

    @Override
    public void setProperties(Properties properties) {
        this.countSqlParser = ClassUtil.newInstance(properties.getProperty("countSqlParser"), CountSqlParser.class, properties, CountJSqlParser45::new);
        this.orderBySqlParser = ClassUtil.newInstance(properties.getProperty("orderBySqlParser"), OrderBySqlParser.class, properties, OrderByJSqlParser45::new);
    }
}

ApplicationRunnerImpl.java:

import com.github.pagehelper.page.PageAutoDialect;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class ApplicationRunnerImpl implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        PageAutoDialect.registerDialectAlias("mysql", LocalMySqlDialect.class);
    }
}

重启再来一发 很好 一波未平一波又起:
在这里插入图片描述
去掉druid连接池filters的wall配置即可:
在这里插入图片描述

重启 搞定~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值