MyBatis绑定错误:Invalid bound statement (not found)
来源:互联网 发布:xp系统链接网络打印机 编辑:程序博客网 时间:2024/06/10 15:43
MyBatis绑定错误:Invalid bound statement (not found)
问题的本质:
用idea建maven项目出现Invalid bound statement (not found)错误,网上找了下发现我的是因为出现map.xml文件与map接口不在同一个文件夹下。问题的发生是由于我把资源文件放在src/main/java/com.Adesk/mapper下,在eclipse中,把资源文件放在src文件夹下,是可以找到的;但是在idea中,直接把资源文件放在src文件夹下,如果不进行设置,是不能被找到的。
我们看下maven为我们打包的target包
我们看到UserMapper.xml并不在里面,即使xxx.xml文件与对应的接口文件不在同一个目录下。也可以理解为maven打包class文件时不打包里面的资源文件,原因是maven有固定放资源文件的目录,resources,这样根据mybatis默认设置是不能进行映射的。
解决办法:
l 方法一
把所有的map.xml文件移动resources目录下,再spring-mvc.xml找到
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
加入如下配置
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
图如下
有些项目可能不在spring-mvc.xml中注入dataSource,那就自己找
l 方法二
这种就不是解决该错误的办法,而是换另一种方式查数据库,如果你觉得通过映射文件比较麻烦那么这里有一种注解的方式,就是直接在map接口中写sql语句通过注解的方式,那么就省掉了map.Xml文件,
相对于自己写sql语句来说,个人认为之中方式比较好用,但是mybatis的逆向工程也是挺好的。个人喜好。
- MyBatis绑定错误:Invalid bound statement (not found)
- mybatis绑定错误-- Invalid bound statement (not found)
- MyBatis绑定错误--BindingException:Invalid bound statement (not found)
- MyBatis绑定错误:Invalid bound statement (not found)
- mybatis绑定错误-- Invalid bound statement (not found)
- mybatis绑定错误-- Invalid bound statement (not found)
- mybatis错误: Invalid bound statement (not found)
- mybatis错误:Invalid bound statement (not found)
- mybatis错误:Invalid bound statement (not found)
- mybatis错误:Invalid bound statement (not found)
- mybatis错误 Invalid bound statement (not found)
- [MyBatis]Invalid bound statement (not found)错误
- mybatis错误:Invalid bound statement (not found)
- MyBatis Invalid bound statement (not found)错误
- mybatis错误:Invalid bound statement (not found)
- mybatis错误:Invalid bound statement (not found)
- mybatis绑定错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis绑定错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Leetcode之Remove Nth Node From End of List 问题
- 软件工程(C编码实践篇)”实验报告 实验二:命令行菜单小程序V1.0
- java中插入汉字到mysql中变成?的处理办法
- Java之多线程CountDownLatch 用法 -yellowcong
- 练习题(基础练习)
- MyBatis绑定错误:Invalid bound statement (not found)
- OpenCV 张正友标定法的实现
- N皇后问题
- 【数据结构】【OI】二项堆的原理及代码实现
- asp.net创建helloWord
- HQL 多表联合查询
- JavaScript中forEach、for-in、for-of循环的比较
- 使用pyspark进行机器学习(回归问题)
- 1.break 2.continue 3. return