解决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. 微信小程序基础知识笔记

    微信小程序笔记 文件构成 全局文件 app.json 小程序全局配置文件,必要,自动生成 app.js 小程序入口JS文件,一般只需申明全局变量.处理生命周期以及版本升级即可,必要 app.wxss ...

  2. 代码保留格式(高亮)复制到Word(转载)

    将代码保持高亮复制粘贴到word上,一些方法如下: 方法一:借助网站http://www.planetb.ca/syntax-highlight-word/(代码有编号,整体排版精美令人舒适,但语言有 ...

  3. 命令行解析函数:getopt_long、getopt

    一.前言 在学习一些项目代码时,尤其涉及到命令行传参的代码,经常遇到getopt相关的函数,对这一类函数可以说是既陌生又熟悉.陌生是因为不知道它是干啥的,熟悉呢,是因为经常遇到.于是乎在追踪了多天ip ...

  4. VUE005. 在data中使用 / 改变data,或在data中调用method函数

    使用三方UI库时经常会遇到在data中写入方法的场景,如Element-UI的级联选择器(动态加载part)需要在data中写入lazyLoad. 但后端总会给出意想不到的需求: 通过接口调取一串数据 ...

  5. 枚举类enum

    一.枚举类 package com.xxx.xf.common.enums; import com.xxx.xf.workday.contant.HolidayContant; /** * @Auth ...

  6. [第十二篇]——Docker Dockerfile之Spring Cloud直播商城 b2b2c电子商务技术总结

    Docker Dockerfile 什么是 Dockerfile? Dockerfile 是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明. 使用 Dockerfile 定制 ...

  7. 微信小程序+腾讯云直播的实时音视频实战笔记

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  8. 本地文件名大写,提交到git仓库后变成了小写

    输入改命令即可: git config core.ignorecase false

  9. javascript,jquery在父窗口触发子窗口(iframe)某按钮的click事件

    $('iframe').contents().find(".btn").click(); 其中 contents(): 查找匹配元素内部所有的子节点(包括文本节点).如果元素是一个 ...

  10. Shell系列(17)- 配置文件功能(待完善)

    配置文件功能 文件名 功能 相关联命令 /etc/profile USER变量 LOGNAME变量 MAIL变量 PATH变量 HOSTNAME变量 umask 调用/etc/profile.d/*. ...