• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

解决Mybatis-plus和pagehelper依赖冲突的方法示例

java 搞代码 4年前 (2022-01-05) 99次浏览 已收录 0个评论
文章目录[隐藏]

这篇文章主要介绍了解决Mybatis-plus和pagehelper依赖冲突的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

简介

MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作

Mybati-plus本身自带分页功能,但是我个人一直是使用pagehelper进行分页,所以在pom中添加了pagehelper依赖,但是运行项目后发现jar包冲突,面对冲突我们应该怎么解决它呢,看完如下内容便可轻松解决

先看依赖

 <!-- mbatis-plus --> com.baomidoumybatis-plus-boot-starter3.1.2<!--generator--> com.baomidoumybatis-plus-generator3.1.2<!-- pagehelper--> com.github.pagehelperpagehelper-spring-boot-starter1.2.5

运行项目

***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.getLanguageDriver(MybatisMapperAnnotationBuilder.java:369)
The following method did not exist:
com.baomidou.mybatisplus.core.MybatisConfiguration.getLanguageDriver(Ljava/lang/Class;)Lorg/apache/ibatis/scripting/LanguageDriver;
The method’s class, com.baomidou.mybatisplus.core.MybatisConfiguration, is available from the following locations:
jar:file:/Applications/MrWang/Maven/privite_wang_repository/com/baomidou/mybatis-plus-core/3.1.2/mybatis-plus-core-3.1.2.jar!/com/baomidou/mybatisplus/core/MybatisConfiguration.class
It was loaded from the following location:
file:/Applications/MrWang/Maven/privite_wang_repository/com/baomidou/mybatis-plus-core/3.1.2/mybatis-plus-core-3.1.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.baomidou.mybatisplus.core.MybatisConfiguration
Disconnected from the target VM, address: ‘127.0.0.1:55790’, transport: ‘socket’
Process finished with exit code 0

纠正应用程序的类路径,使其包含com.baomidou.mybatisplus.core.MybatisConfiguration的单一兼容版本

标红的部分是灰色的,看后面括号中的意思 (为冲突而生 ),这个包跟上面的包是一样的,上面是亮的,下面是灰色的,说明系统用了上面的jar包,导致下面jar包提示冲突,但为什么不用下面的,自己私下花点时间 研究一下,当然我们的目的不是解决这个冲突,因为这个被系统检测出来了,系统自动停用了一个,我们要解决系统检测不出来的冲突

引入 MyBatis-Plus 之后请不要再次引入 MyBatis 以及 MyBa来源gaodai$ma#com搞$$代**码)网tis-Spring,以避免因版本差异导致的问题。(Mybatis-plus官网原话)

pagehelper依赖包中由上图得知,也是包含了MyBatis 以及 MyBatis-Spring,而MyBatis-Spring依赖冲突,系统自动用了Mybatis-plus中的MyBatis-Spring,所以我们只需要把pagehelper中的mybatis依赖删除即可,具体操作如下

在version 下面添加 exclusions依赖(排除)

 <!-- pagehelper--> com.github.pagehelperpagehelper-spring-boot-starter1.2.5  org.mybatismybatis

重启项目并测试

postman测试结果

 问题完美解决了

以上就是解决Mybatis-plus和pagehelper依赖冲突的方法示例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:解决Mybatis-plus和pagehelper依赖冲突的方法示例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址