解决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. python 动图gif合成与分解

    合成 #!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import sys import imageio def main(imgs_ ...

  2. Blazor 组件库开发指南

    翻译自 Waqas Anwar 2021年5月21日的文章 <A Developer's Guide To Blazor Component Libraries> [1] Blazor 的 ...

  3. 运输层协议:TCP连接建立与释放

    TCP的特点 面向连接:TCP是面向连接的运输层协议,通过TCP发送数据需要先建立连接,通信结束后需要释放连接 可靠传输:TCP实现了可靠传输,使得数据能够无丢失.无差错.不重复地到达接收端 面向字节 ...

  4. Vue+element基本增删改查

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  5. Spring基于XML方式加载Bean定义信息(又名:Spring IOC源码时序图)-图解

  6. Tomcat部署与优化

    目录: 一.Tomcat概述 二.Tomcat 服务部署 三.Tomcat 虚拟主机配置 四.Tomcat 优化 一.Tomcat概述 Tomcat是Java语言开发的,Tomcat服务器是-个免费的 ...

  7. TP6出现错误 No input file specified.

    解决办法是打开public下的.htaccess文件, 把:RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 改为:RewriteRule ^(.*)$ index ...

  8. 队列,一种"公平"的数据结构

    路过一家奶茶店,由于生意火爆,门口的排着长长的队伍,先排队的人先买到奶茶,然后再轮到下一个,秩序井然.有没有一种数据结构能体现"先来后到"这种顺序呢? 当然有,那就是队列.先看一下 ...

  9. jmeter加密解密(解密篇)

    上一篇已经讲解了公钥加密,这篇讲解公钥解密.解密比较简单,直接操作吧. 需求是:接口中的请求体的部分参数需要先加密再请求,返回的结果中部分字段需解密. 1.在请求下新建beanshell后置处理程序, ...

  10. P5488-差分与前缀和【NTT,生成函数】

    正题 题目链接:https://www.luogu.com.cn/problem/P5488 题目大意 求一个长度为$n$的序列的$k$阶差分/前缀和. 解题思路 先考虑前缀和怎么做 搞出来生成函数就 ...