mybatis plus解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)方法
总结解决 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)方法
问题背景:在做SpringBoot项目的时候,通过controller层调用service层的接口时出现了如下的报错
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.service.UserService.getById
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.2.jar:3.5.2]
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:49) ~[mybatis-plus-core-3.2.0.jar:3.2.0]
at com.example.controller.UserController.obj(UserController.java:18) ~[classes/:na]
1.问题原因
通过网上搜索到的报错原因,本质原因是由于dao层(也可以叫做mapper接口)跟mapper.xml文件没有映射,而大部分的原因有如下的几种类型:
- dao层的方法跟mapper.xml的方法不一样
- mapper.xml中的namespace 要写对应的dao层和entity层不一样
- spring配置文件中mybatis与xml文件路径的配置没有写,导致无法映射成功
- 拼写错误导致
2.解决方法
2.1方法1:
Mypatis配置文件有问题,在application.yml添加如下代码:
mybatis-plus:
mapper-locations: classpath*:com/example/mapper/xml/*Mapper.xml
mapper-locations的路径要对应响应 .xml 文件所在路径
2.2方法2:
在pom.xml 文件下加入如下代码:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
这上部分的解决方法应该能解决大部分的service层报错的问题,但是这上面的方法并不能解决我的问题。通过我继续对其研究,发现在我的一个扫描Mapper配置文件中路径错误
这是由于配置的base-package范围太大,导致service层的接口也被包装了,将base-package的范围缩小到dao层既可以解决了
将其修改到对应的dao层路径后问题就得以解决了
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhghaiec
系列文章
更多
同类精品
更多
-
JavaWeb实现文件上传和下载
-
解决Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources......
-
PageOffice在线编辑office文件和Apache POI的区别
-
Apache HTTP Server <2.4.56 mod_proxy 模块存在请求走私漏洞CVE-2023-25690
-
dolphinscheduler 3.0.1代码下载编译和部署
-
Exception in thread “main“ java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$PO
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
怎样阻止微信小程序自动打开
PHP中文网 06-13