栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

总结mybatis plus解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)方法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

总结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.(MapperMethod.java:235) ~[mybatis-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.(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*.xml
			
			false
		
		
			src/main/resources
			
				***.xml
			
			false
		
	

这上部分的解决方法应该能解决大部分的service层报错的问题,但是这上面的方法并不能解决我的问题。通过我继续对其研究,发现在我的一个扫描Mapper配置文件中路径错误


这是由于配置的base-package范围太大,导致service层的接口也被包装了,将base-package的范围缩小到dao层既可以解决了

将其修改到对应的dao层路径后问题就得以解决了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/735796.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号