Mybatis - 在idea中错误:Invalid bound statement (not found)
来源:互联网 发布:php源码分享 编辑:程序博客网 时间:2024/05/19 14:20
学习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中添加过滤:
<!--配置Maven 对resource文件 过滤 --> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> </resources>
我采用mybatis的自动代理设置,将mapper文件和xml文件同名同包下,并在sqlMap.xml(mybatis-config.xml)中配置mapper自动注册扫描包:
<mappers> <mapper resource="sqlmap/User.xml"/> <!--通过resource方法一次加载一个映射文件 --> <!--<mapper resource="sqlmap/UserMapper.xml"/>--> <!-- 通过mapper接口加载单个 映射文件 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中 上边规范的前提是:使用的是mapper代理方法 --> <!--<mapper class="cn.itcast.mybatis.mapper.UserMapper"/>--> <!-- 批量加载mapper 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中 上边规范的前提是:使用的是mapper代理方法 --> <package name="cn.itcast.mybatis.mapper"/> </mappers>
不管是在多modul 下进行配置还是单个工程下,均是这样配置;
idea 的 多modul 下 ,只需要在 root 项目的 maven 下进行配置即可! 当然配置在 pom.xml 中的 标签下!
example :
<build> <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.7</version> <configuration> <connectors> <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> <port>8888</port> <maxIdleTime>30000</maxIdleTime> </connector> </connectors> <webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}</webAppSourceDirectory> <contextPath>/</contextPath> </configuration> </plugin> </plugins> <!--这里进行配置,后会自动的加载mapper.xml文件 :配置Maven 对resource文件 过滤 --> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> </resources> </build>
- 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)问题
- hibernate5(10)注解映射[2]一对多单向关联
- LeetCode Merge Two Sorted Lists
- 3.1.14 文件锁
- JAVA数据源连接方式汇总
- android:ToolBar详解
- Mybatis - 在idea中错误:Invalid bound statement (not found)
- 30个css选择器(带兼容性情况)
- maven常用命令
- iOS中造成dealloc不调用的原因
- C++实验三项目一
- 3.1.15 结构体的交互引用
- 1010. Radix (25)
- struts2中自定义拦截器
- 揭开“流量劫持”的神秘面纱