Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser 解决方案
在配置MyBatis时报错信息如下:
Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser
简单的理解就是找不到正确的语句。一般是由于mapper.xml和mapper.java的文件不匹配造成的。引入映射器大致有四种方法:
1.用文件路径引入映射器
<mapper resource="com/shizongger/chapter2/mapper/RoleMapper.xml" />
<mapper resource="com/shizongger/chapter2/mapper/UserMapper.xml" />
2.用包名引入映射器
<package name="com.shizongger.chapter2.mapper" />
3.用类注册引入映射器
<mapper class="com.shizongger.chapter2.mapper.UserMapper" />
<mapper class="com.shizongger.chapter2.mapper.RoleMapper"/>
4.xxxMapper.xml引入映射器
<mapper url="file:/home/shizongger/workspace/Chapter3/src/com/shizongger/chapter2/mapper/RoleMapper.xml" />
<mapper url="file:/home/shizongger/workspace/Chapter3/src/com/shizongger/chapter2/mapper/UserMapper.xml"/>
这四种引入mapper的方式各有特点,我建议使用第一种或者第二种使用扫描的包的方式。但是在使用第二种的时候要注意:一定要把xxxMapper.java和xxxMapper.xml两者名字一模一样!
本次报错的原因是因为本人把UserMapper.xml错写成userMapper.xml,开头使用了小写,导致程序扫描包的时候扫描不到该mapper而出错。

我为什么会犯此错误?因为我在参考《深入浅出MyBatis技术原理与实践》(电子工业出版社-杨开振著)第3章57页的时候,作者给出了userMapper.xml的代码案例,并以小写作为userMapper.xml文件的开头。且在72页用到mapper.xml的地方,作者都有小写作为mapper.xml开头的习惯。本人误认为是MyBatis默认要求符合驼峰命名法且第一字母必须小写而导致的。
所以,在这里奉劝写技术书籍的作者不要浮躁,要对得起读者啊!
Invalid bound statement (not found): com.shizongger.chapter2.mapper.UserMapper.insertUser 解决方案的更多相关文章
- Invalid bound statement (not found): com.my.demo.mapper.UserMapper.getAll
网上的方法全试了,配置全对,很奇怪. 最后一查,竟然忘记把mapper保存为xml格式. 记录一下.
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.e3mall.search.mapper.ItemMapper.getItemList
java.lang.RuntimeException: org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
- Invalid bound statement (not found) 找不到mapper 映射文件异常
访问页面报如下错(注意第一行后面的 invalid bound statement (not found)) 这时候再mapper的pom.xml文件要加如下. 否则该节点mybatis的mapper ...
- Invalid bound statement (not found): com.example.managerdemo.mapper.SingleTableMapper.selectAllValuesByConditionsNoPage
报Invalid bound statement (not found): com.example.managerdemo.mapper.SingleTableMapper.selectAllValu ...
- 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add
报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.i ...
- 奇葩问题:Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey
使用mybatis,遇到Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey ...
- 解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)
一.问题描述 使用mybatis的项目在本地可以正常运行,但当使用maven或Jenkins打包部署到服务器上时出现了绑定错误,异常信息为: org.apache.ibatis.binding.Bin ...
- Mybatis中的Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 找不到Mapper.xml文件的问题
1 首先在配置mapper-locations的时候: classpath: 只在现有目录下寻找配置文件 classpath*: 在现有的项目目录下和依赖的jar包下寻找xml配置文件
- Invalid bound statement (not found): com.up.sell.mapper.system.H5operationMapper.
springboot + mybatis项目,出现这样的错误原因就是mapper类的名字和xml的id不对应或者是忘记写了,仔细检查一下吧
随机推荐
- 关于C语言中static保留字的使用
static存储类型可以用于全部变量,无需考虑变量声明的位置.但是作用于块外部和块内部时具有不同的作用. (1)当作用于函数内部时,和每次程序离开所在块就会丢失值的自 ...
- db2服务器端授权
昨天吃饭回来有点晚,没有及时写,今天补上. db2服务器端安装就不说了,网上很多.今天具体说说授权吧.这是个麻烦事. 安装的时候会让你创建数据库.你就根据提 ...
- 关于hash和ico的一些关联
最近測试提出一个bug.说某几个页面中的ico不显示,于是针对此问题排查原因. 首先,确保页面中的link已引入favicon.ico. 经查看,发现是js中的location.hash导致了ico不 ...
- JAVA入门[6]-Mybatis简单示例
初次使用Mybatis,先手写一个hello world级别的例子,即根据id查询商品分类详情. 一.建表 create table Category ( Id INT not null, Name ...
- exports 和 module.exports
首先参考一个js的示例 app.js var a = {name: 'nswbmw 1'}; var b = a; console.log(a); console.log(b); b.name = ' ...
- android 分享一个处理BaseAdapter,getView()多次加载的方法
一:BaseAdapter介绍 BaseAdapter是listview,gridview等列表,使用的数据适配器,它的主要用途是将一组数据传到ListView.Spinner.Gallery及Gri ...
- 基于.NET的弹性及瞬间错误处理库Polly
本文基本是官方说明的翻译和总结(https://github.com/App-vNext/Polly) 什么是Polly? Polly是一款基于.NET的弹性及瞬间错误处理库, 它允许开发人员以顺畅及 ...
- Mixed Reality-宁波市VR/AR技术应用高研班总结
年,全球AR与VR市场规模将达到1500亿美元,而根据市场研究机构BI Intelligence的统计,2020年仅头戴式VR硬件市场规模将达到28亿美元,未来5年复合增长率超过100%.本次培训从V ...
- .Net 关于 InfoPath 的基本使用
最近几天接触微软的 InfoPath 表单工具,结合VS 使用,遇到的一些问题与解决方法,记录一下,百度上的内容很少,或许我根本不知道咋搜,所有也留一个网页帮助自己使用当然使用的时候碰到了好几个坑: ...
- free查看内存和swap使用情况,增加、删除、自动挂载swap分区
free [root@localhost ~]# free total used free shared buff/cache available Mem: 999936 142760 566536 ...