解决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. Android Parsing between JSON and Kotlin Object with Google Gson Library

    Parsing between JSON and Kotlin Object with Google Gson Library dependencies { ... implementation 'c ...

  2. Robot Framework 面试题

    什么是 RF 基于可扩展关键字驱动的自动化测试框架 什么是可扩展关键字驱动 可扩展意味着可以自己开发,也可以调用第三方的关键字库 关键字驱动意味着测试用例都是围绕着关键字运行的 RF 的原理(框架?) ...

  3. Flask - 访问返回字典的接口报错:The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict.

    背景 有一个 Flask 项目,然后有一个路由返回的是 dict 通过浏览器访问,结果报错 关键报错信息 TypeError: 'dict' object is not callable The vi ...

  4. ysoserial CommonsColletions6分析

    CC6的话是一条比较通用的链,在JAVA7和8版本都可以使用,而触发点也是通过LazyMap的get方法. TiedMapEntry#hashCode 在CC5中,通过的是TiedMapEntry的t ...

  5. 忘记root密码的情况下如何给指定账户开通远程访问

    1.跳过验证使用root登录 net stop mysql //停止MYSQL服务 打开第一个cmd窗口,切换到mysql的bin目录,运行命令: mysqld --defaults-file=&qu ...

  6. confluence 开源破解

    一.安装 (一).开源agent   https://gitee.com/pengzhile/atlassian-agent (二).dockerfile FROM cptactionhank/atl ...

  7. js相同的正则多次调用test()返回的值却不同的问题

    js代码: var name = '测试中文';// 姓名 var nameRgexp = new RegExp("[a-zA-Z\u4e00-\u9fa5]{2,}"," ...

  8. C# MVC 实现 ajax 跨域

    dataup.js$(function() {    $.ajax({        url: "http://localhost:1266/test/t",        dat ...

  9. git 切换分支

      # 查看git源 git  remote -v git remote set-url origin http://mingzhanghui@xx.xx.xx.xx:8090/r/ENSO/weba ...

  10. tornado中通用模版

    第一: 1.Pycharm新建python项目(不是django项目),在项目下面直接新建server.py,内容如下: 2.安装tornado, pip install tornado import ...