在配置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 解决方案的更多相关文章

  1. Invalid bound statement (not found): com.my.demo.mapper.UserMapper.getAll

    网上的方法全试了,配置全对,很奇怪. 最后一查,竟然忘记把mapper保存为xml格式. 记录一下.

  2. 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 ...

  3. Invalid bound statement (not found) 找不到mapper 映射文件异常

    访问页面报如下错(注意第一行后面的 invalid bound statement (not found)) 这时候再mapper的pom.xml文件要加如下. 否则该节点mybatis的mapper ...

  4. Invalid bound statement (not found): com.example.managerdemo.mapper.SingleTableMapper.selectAllValuesByConditionsNoPage

    报Invalid bound statement (not found): com.example.managerdemo.mapper.SingleTableMapper.selectAllValu ...

  5. 【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 ...

  6. 奇葩问题:Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey

    使用mybatis,遇到Invalid bound statement (not found): cn.zss.zsdemo.mapper.RoleMapper.selectByPrimaryKey ...

  7. 解决Invalid bound statement (not found)(Mybatis的Mapper绑定问题)

    一.问题描述 使用mybatis的项目在本地可以正常运行,但当使用maven或Jenkins打包部署到服务器上时出现了绑定错误,异常信息为: org.apache.ibatis.binding.Bin ...

  8. Mybatis中的Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 找不到Mapper.xml文件的问题

    1 首先在配置mapper-locations的时候: classpath:  只在现有目录下寻找配置文件 classpath*: 在现有的项目目录下和依赖的jar包下寻找xml配置文件

  9. Invalid bound statement (not found): com.up.sell.mapper.system.H5operationMapper.

    springboot + mybatis项目,出现这样的错误原因就是mapper类的名字和xml的id不对应或者是忘记写了,仔细检查一下吧

随机推荐

  1. jq获取今天、昨天、一周时间

    不少后台文章管理系统就有今天.明天.一周内.全部的分类展示,用Jquery获取今天.明天.一周内的时间节点(如下图) html页面代码: <div class="date-list-c ...

  2. Xamarin 使用极光推送 详细教程

    源码下载地址:http://download.csdn.net/download/kendocross/8677263  有兴趣的看以去看看 一.首先新建一个Xamarin.Android 项目,过程 ...

  3. Android Things 专题6 完整的栗子:运用TensorFlow解析图像

    文| 谷歌开发技术专家 (GDE) 王玉成 (York Wang) 前面絮叨了这么多.好像还没有一个整体的概念.我们怎样写一个完整的代码呢? 如今深度学习非常火,那我们就在Android Things ...

  4. HDOJ 4251 The Famous ICPC Team Again

    划分树水题..... The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 3276 ...

  5. Asp.net MVC 填充word并下载

    使用Aspose.word填充内容并下载(免费版Aspose) 填充固定模式的Word文档,需要先制作Word模板: Aspose.Words主要通过Words里域(Fields)来控制内容.     ...

  6. Python笔记·第五章—— 列表(List) 的增删改查及其他方法

    一.列表的简介   列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[ ]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如:li = ...

  7. 一个简单的双向链表(C++实现)

    直接上代码,亲测有用. #ifndef __DLINK_H__ #define __DLINK_H__ /* [phead] -> [index0] -> [index1] -> [ ...

  8. python自动化--字符串和整数的转换,while的循环体

    字符串(str)和整数(int)类型变量的结合 *遵循只有同一类型的变量才可以结合. *不同类型的变量之间的转换 实例:实现打印出"192.168.100"和1的结合出" ...

  9. 使用Myeclipse为数据表创建hibernate实体对象

    hibernate是orm框架的一种,orm即Object Relational Mapping,对象映射关系,其主要作用是将数据库(mysql,mssql,oracle)的对象转换为具体编程语言(如 ...

  10. 数据从文件导入Elasticsearch

    1.资源准备 1.数据文件:accounts.json 2.索引名称:bank 3.数据类型:account 4.批量操作API:bulk 2.导入数据 curl -XPOST 'localhost: ...