升级mybatisplus从3.1.2到3.5.2错误修复记录
- 原来的mybatis-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="logImpl" value="SLF4J"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<plugins>
<!-- 分页插件 -->
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor">
</plugin>
<!-- 乐观锁插件 -->
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor">
</plugin>
</plugins>
</configuration>
升级mybatisplus从3.1.2->3.5.2版本后,PaginationInterceptor和OptimisticLockerInterceptor类找不到,查找新包以后,这两个类和路径已经改了,再改成:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="logImpl" value="SLF4J"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<plugins>
<!-- 分页插件 -->
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor">
</plugin>
<!-- 乐观锁插件 -->
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor">
</plugin>
</plugins>
</configuration>
发现还是报错,提示:PaginationInnerInterceptor cannot be cast to org.apache.ibatis.plugin.Interceptor
查看官方文档,需要这样配置才正确:
- 正确的xm配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="logImpl" value="SLF4J"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<plugins>
<plugin interceptor="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
<!-- 分页插件 -->
<property name="@page" value="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"/>
<!-- 乐观锁插件 -->
<property name="@version" value="com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor"/>
</plugin>
</plugins>
</configuration>