解决Mybatis 报错Invalid bound statement (not found)

出现此错误的原因

1.xml文件不存在

2.xml文件和mapper没有映射上

  • namespace指定映射mapper的路径错误
  • id和mapper中的方法名不一致

3.xml文件在java目录下而不在resource目录下,因此生成target中无xml

场景

​ 在使用Mybatis-plus框架时,自定义mapper接口和xm文件时,由于使用的是MP的自动生成代码插件,导致mapper接口和xml文件都在java目录下,而在编译时,在java路径下的xml文件不会被自动编译进去,编译只会识别.java文件,只有在resource下的xml文件在打包时才能编译进去。

下图是MP自动生成代码插件的xml和mapper目录(不再resource中)

而编译出来的target目录下是这样的:

解决方法:

1.在pom文件中添加

    <build>
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

2.手动将java目录下的xml文件移到resource目录下,并且在Spring Boot中的配置文件中加入

mybatis-plus:
mapper-locations: classpath:**/*.xml //classpath后添加你xml文件的目录

注意:博主血的教训!!!

mapper-locations中的目录一定要是你放置xml文件的目录一致,否则就算target中存在xml文件,也会出现这个错误!!!

由于本人能力有限,欢迎访问个人博客,进行技术交流,如有不足,欢迎指正~

解决Mybatis 报错Invalid bound statement (not found)的更多相关文章

  1. springboot+mybatis报错Invalid bound statement (not found)

    今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql:原因是程序没有把.xml文件编译 ...

  2. MybatisPlus报错Invalid bound statement (not found)的解决方案

    今天使用MybatisPlus,测试时报错Invalid bound statement (not found) 使用自定义的mapper接口中的方法可以执行,而调用MybatisPlus中baseM ...

  3. 使用Mybatis时报错Invalid bound statement (not found):

    使用逆向工程时生成的.xml文件在conf目录下,而使用查询方法时,无法在dao包下找到xml文件,所以报错. 测试代码如下所示: @Test public void testSimple() thr ...

  4. IDEA maven项目下测试mybatis例子,使用mappper class或package引入mapper映射文件,总是报错Invalid bound statement(所有配置完全正确)

    困扰几个小时,终于查到解决办法及原因(可以直接到最后看解决方案) 环境就是用IDEA搭建的maven项目,主要jar包引入配置如下 <dependencies> <dependenc ...

  5. Mybatis plus 报错Invalid bound statement (not found) 终极解决办法

    我产生的错误原因是写的mapper继承BaseMapper没有添加泛型: 点进去: 为了解决这个bug,网上很多人也提出了解决办法:1.检查xml文件的namespace是否正确 2.Mapper.j ...

  6. [mybatis] mybatis错误:Invalid bound statement (not found)

    点击菜单抛出异常: org.springframework.web.util.NestedServletException: Request processing failed; nested exc ...

  7. mybatis 异常处理:Invalid bound statement (not found)

    mybatis 的使用过程中提示错误: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): ...

  8. MyBatis绑定错误[Invalid bound statement (not found)]

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...

  9. MyBatis 错误:Invalid bound statement (not found)

    错误: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zr.msgg.per ...

随机推荐

  1. springMVC学习总结(一) --springMVC搭建

    springMVC学习总结(一) --springMVC搭建 搭建项目 1.创建一个web项目,并在项目中的src文件夹下创建一个包com.myl.controller. 2.添加相应jar包 3.在 ...

  2. shell脚本之case语句

    case ... esac 为多选择语句,与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构,每个 case 分支用右圆括号开始,用两个分号 ;; 表示 break,即执行 ...

  3. Python3正则表达式学习笔记

    学习前准备:导入re模块 import re 一.re的核心函数 1 - re.compile(pattern[, flags]) 编译正则表达式,速度快 2 - re.match(pattern, ...

  4. Python - 通过PyYaml库操作YAML文件

    PyYaml简单介绍 Python的PyYAML模块是Python的YAML解析器和生成器 它有个版本分水岭,就是5.1 读取YAML5.1之前的读取方法 def read_yaml(self, pa ...

  5. Docker安装mysql镜像并进行主从配置

    Docker安装mysql镜像并进行主从配置 1.下载需要的mysql版本镜像 docker pull mysql:5.6 2.启动mysql服务实例(基本启动) #启动主mysql docker r ...

  6. list使用详解

    List双向链表 再谈链表 List链表的概念再度出现了,作为线性表的一员,C++的STL提供了快速进行构建的方法,为此,在前文的基础上通过STL进行直接使用,这对于程序设计中快速构建原型是相当有必要 ...

  7. Shell系列(36)- for循环语法二简介及批量添加删除用户

    for循环语法二 for ((初始值;循环控制条件;变量变化)) do 程序 done 例子 例子-1 求和工具 需求:根据用户输入的数字,求1~输入所有数字的和 脚本: #!/bin/bash re ...

  8. 重磅来袭!!!Elasticsearch7.14.1(ES 7.14.1)与Springboot2.5.4的整合

    1. 概述 前面我们聊了 Elasticsearch(ES)集群的搭建,今天我们来聊一下,Elasticsearch(ES)集群如何与 Springboot 进行整合. Elasticsearch(E ...

  9. MSSQL数据库安全实验

    管理SQL Server认证模式 (1)确认 SQL Server 验证 ①在桌面上单击"开始",选择"程序"→"Microsoft SQL Serv ...

  10. php无限分类 构建树形结构

    <?php class Classification { const PARENT_ID = 'parentid'; const ID = 'id'; const CHILDREN = 'chi ...