IDEA报错: Invalid bound statement (not found): com.test.mapper.UserMapper.selectByPrimaryKey(转发:https://www.cnblogs.com/woshimrf/p/5138726.html)
学习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 <!-- 批量加载mapper
13 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载
14 遵循一些规范:需要将mapper接口类名和mapper.xml映射文件名称保持一致,且在一个目录 中
15 上边规范的前提是:使用的是mapper代理方法
16 -->
17 <package name="cn.itcast.mybatis.mapper"/>
18
19 </mappers>
测试通过,解决了心头的疙瘩。
IDEA报错: Invalid bound statement (not found): com.test.mapper.UserMapper.selectByPrimaryKey(转发:https://www.cnblogs.com/woshimrf/p/5138726.html)的更多相关文章
- 解决Mybatis 报错Invalid bound statement (not found)
解决Mybatis 报错Invalid bound statement (not found) 出现此错误的原因 1.xml文件不存在 2.xml文件和mapper没有映射上 namespace指定映 ...
- IDEA+Maven+Mybatis 巨坑:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.UserMapper.findAll
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.rao.mapper.User ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shen.mapper.UserMapper.findById
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shen.mapper.Use ...
- Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey
Invalid bound statement (not found): com.taotao.mapper.TbItemMapper.selectByPrimaryKey Invalid bound ...
- MybatisPlus报错Invalid bound statement (not found)的解决方案
今天使用MybatisPlus,测试时报错Invalid bound statement (not found) 使用自定义的mapper接口中的方法可以执行,而调用MybatisPlus中baseM ...
- springboot+mybatis报错Invalid bound statement (not found)
今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql:原因是程序没有把.xml文件编译 ...
- IDEA maven项目下测试mybatis例子,使用mappper class或package引入mapper映射文件,总是报错Invalid bound statement(所有配置完全正确)
困扰几个小时,终于查到解决办法及原因(可以直接到最后看解决方案) 环境就是用IDEA搭建的maven项目,主要jar包引入配置如下 <dependencies> <dependenc ...
- Mybatis plus 报错Invalid bound statement (not found) 终极解决办法
我产生的错误原因是写的mapper继承BaseMapper没有添加泛型: 点进去: 为了解决这个bug,网上很多人也提出了解决办法:1.检查xml文件的namespace是否正确 2.Mapper.j ...
- Invalid bound statement (not found): com.zheng.mapper.UserMapper.login
错误的原因:mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到. mapper接口开发规范 1.Mapper.xm ...
随机推荐
- inspect模块详解
inspect模块主要提供了四种用处: (1).对是否是模块,框架,函数等进行类型检查. (2).获取源码 (3).获取类或函数的参数的信息 (4).解析堆栈 使用inspect模块可以提供自省功能, ...
- Linux下实现文件双向同步
修改的地方时:私钥和公约处. 其次 vi /root/.unison/default.prf 这个文件在这个位置 root = /tmp/test root = ssh://root@10.10.3. ...
- 【Excle】如何隐藏数据透视表中的错误值
如下:数据透视表出现错误 怎么解决呢 步骤 方法① 单击数据透视表任意单元格→数据透视表工具→分析→选项→勾选"对于错误值显示"→确定 方法② 右键→数据透视表选项(同样可以修改)
- Android事件的分发
1 http://blog.csdn.net/guolin_blog/article/details/9097463 2
- 搭建SSH框架整合Struts2和Spring时,使用@Autowired注解无法自动注入
© 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述: 搭建SSH框架,在进行Struts2和Spring整合时,使用Spring的@Autowired自动注入失败,运行报错java.lan ...
- ubuntu openfire Server install
1.首先登录到ubuntu server.在安装openfire 服务器之前,先确保你的系统已经更新到最新.然后输入下面的命令,一行一行执行,最后安装可用的更新 sudo apt-get update ...
- WPF 员工卡条形码
大家都知道条形码(Barcode)是一种可以由机器识别的特殊编码,在生产.生活中也常常会见到并使用它.条形码的类型和种类很多感兴趣的朋友可以详细了解一下.其中Code 39 可以说是一种最为常见并广泛 ...
- 下载某资源文件并加载其中的所有Prefab到场景中
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...
- C语言基础知识【程序结构】
C 程序结构1.C 程序主要包括以下部分:预处理器指令函数变量语句 & 表达式注释2.#include <stdio.h> int main(){ /* 我的第一个 C 程序 ...
- gridControl使用集锦
1.grid控件默认选择一行时,focused的cell并不是蓝色的,而是白色的 要想实现一次选择一行全都是蓝色的只要改一个属性就可以了 this.gridView1.OptionsSelection ...