在配置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. js内置构造函数属性修改问题

    在学习js原型时遇到一个问题,Array,Object等内置构造函数部分属性无法修改,我猜测可能是因为浏览器实现的原因造成的. 1.修改name属性无效. <script type=" ...

  2. 鼠标悬停,图片放大 CSS实现

    因为最近做的项目刚好用到了这个实现,分享出来   class=enlarge 为div标签的class div img 为标签 .enlarge div img:hover{ transform: s ...

  3. 掌上快递 APP 项目之概述篇

    概述 学习Android开发也有一段时间了,利用业余时间独立制作的一款快递类APP软件.大概2个多星期吧,自己将其定位为"集快递信息追踪.附近快递点查询. 快递公司投诉功能为一体的便民生活类 ...

  4. 1692: [Usaco2007 Dec]队列变换|后缀数组|贪心

    将字符串翻转后接到原串的后面,中间加一个分隔符,每次都贪心选择rankrank小的那个 事实上就是练习一发后缀数组的模板 #include<algorithm> #include<i ...

  5. EL表达式的简单实用

    EL表达式 EL(Expression Language) 是为了使JSP写起来更加简单.表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方 ...

  6. hbase分布式集群搭建

    hbase和hadoop一样也分为单机版.伪分布式版和完全分布式集群版本,这篇文件介绍如何搭建完全分布式集群环境搭建. hbase依赖于hadoop环境,搭建habase之前首先需要搭建好hadoop ...

  7. HTML5 高级系列:web Storage

    前言 HTML5 的 web Storage 存储方式有两种:localStorage 和 sessionStorage. 这两种方式都是通过键值对保存数据,存取方便,不影响网站性能.他们的用法相同, ...

  8. Mybatis-Oralce批量插入方法

    mybatis-Oralce 中批量插入方法一:<insert id="insertBatchSelective" parameterType="java.util ...

  9. Hybris 项目工程配置

    1.控制台页面进入platform目录 cd F:\hybris640\hybris\bin\platform 并运行 setantenv.bat 生成对应的ant. 2.运行 ant moduleg ...

  10. 什么是WAL?

    在写完上一篇<Pull or Push>之后,原本计划这一片写<存储层设计>,但是临时改变主意了,想先写一篇介绍一下消息中间件最最基础也是最核心的部分:write-ahead ...