Mybatis在idea中错误:Invalid bound statement (not found)
来源:互联网 发布:wifi踢人软件 编辑:程序博客网 时间:2024/05/19 11:45
学习mybatis的过程中,测试mapper自动代理的时候一直出错,在eclipse中可以正常运行,而同样的代码在idea中却无法成功。虽然可以继续调试,但心里总是纠结原因。百度了好久,终于找到一个合适的原因。参考:http://blog.csdn.net/z69183787/article/details/48933481;
原因:(参考:http://www.linuxidc.com/Linux/2015-06/118877.htm)
IDEA的maven项目中,默认源代码目录下的xml等资源文件并不会在编译的时候一块打包进classes文件夹,而是直接舍弃掉。
如果使用的是Eclipse,Eclipse的src目录下的xml等资源文件在编译的时候会自动打包进输出到classes文件夹。Hibernate和Spring有时会将配置文件放置在src目录下,编译后要一块打包进classes文件夹,所以存在着需要将xml等资源文件放置在源代码目录下的需求。
解决:
方法1:将xml或properties等配置文件放到resource下,并修改获取配置文件的代码,比如注册mapper.xml的位置等;
方法2:在maven中添加过滤:
1 <!--配置Maven 对resource文件 过滤 --> 2 <resources> 3 <resource> 4 <directory>src/main/resources</directory> 5 <includes> 6 <include>**/*.properties</include> 7 <include>**/*.xml</include> 8 </includes> 9 <filtering>true</filtering>10 </resource>11 <resource>12 <directory>src/main/java</directory>13 <includes>14 <include>**/*.properties</include>15 <include>**/*.xml</include>16 </includes>17 <filtering>true</filtering>18 </resource>19 </resources>
我采用mybatis的自动代理设置,将mapper文件和xml文件同名同包下,并在sqlMap.xml(mybatis-config.xml)中配置mapper自动注册扫描包:
1 <mappers> 2 <mapper resource="sqlmap/User.xml"/> 3 <!--通过resource方法一次加载一个映射文件 --> 4 <!--<mapper resource="sqlmap/UserMapper.xml"/>--> 5 6 <!-- 通过mapper接口加载单个 映射文件 7 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中 8 上边规范的前提是:使用的是mapper代理方法 9 -->10 <!--<mapper class="cn.itcast.mybatis.mapper.UserMapper"/>-->11 12 <!-- 批量加载mapper13 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载14 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中15 上边规范的前提是:使用的是mapper代理方法16 -->17 <package name="cn.itcast.mybatis.mapper"/>18 19 </mappers>
测试通过,解决了心头的疙瘩。
0 0
- Mybatis - 在idea中错误:Invalid bound statement (not found)
- Mybatis在idea中错误:Invalid bound statement (not found)
- Mybatis在idea中错误:Invalid bound statement (not found)
- Mybatis在idea中错误:Invalid bound statement (not found)
- Invalid bound statement (not found)-Mybatis在idea中错误
- 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)
- 新版IntelliJ IDEA中Mybatis报Invalid bound statement (not found)错误解决办法
- IntelliJ IDEA中Mybatis报Invalid bound statement (not found)错误解决办法
- 关于IDEA工具在springboot整合mybatis中出现的Invalid bound statement (not found)问题
- 凹凸映射 Bump mapping(unityshader入门精要学习笔记)
- java字符编码和oracle乱码
- Aspose打印Excel方法代码
- maven中使用junit老是找不到包
- iOS 手势之左右滑动UISwipeGestureRecognizer
- Mybatis在idea中错误:Invalid bound statement (not found)
- Java标识符
- String.split()用法以及特殊分隔符注意,ps:|
- velocity的一些用法
- 错误集锦
- (给自己备忘)常用的5类23种设计模式
- Matlab画图,去掉周围白边
- springmvc学习笔记--mybatis--使用插件自动生成实体和mapper
- js获取网站根目录(虚拟路径)方法