org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误几种解决方案

报错信息:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.study.server.mapper.UserMapper.insert
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
    at com.sun.proxy.$Proxy88.insert(Unknown Source)

根本原因:

一是配置文件,二是注解。


网上总结的一般原因:
Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上。
按以下步骤一一执行:
1、检查xml文件所在的package名称是否和interface对应的package名称一一对应
2、检查xml文件的namespace是否和xml文件的package名称一一对应
3、检查函数名称能否对应上
4、去掉xml文件中的中文注释
5、随意在xml文件中加一个空格或者空行然后保存

项目中的解决方法
第一种可能:在使用IDEA开发时,如果打包时*Mapper.xml没有自动复制到class输出目录的mapper类包下,则需要在pom文件中添加mybatis加载配置文件的配置!
如下:

<build>
  <resources>
    <resource>
        <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
    </resource>
    <resource>
      <directory>src/main/resources</directory>
    </resource>
  </resources>
</build>

通过在pom文件中添加mybatis加载配置文件,完美解决遇到的问题了

第二种可能:如果你的项目类似功能无问题,那么问题可能出在了mybatis配置问题,加载mapper.xml时出来问题。

        <mapper resource="mybatisMapper/GiftTypeEntityMapper.xml"></mapper>
        
        

以上方案则为博主查找到的解决此问的所有方法


上文出自胖胖,转载请附带原文链接

后续更新自学的方法,以及java知识总结
我是哪怕前路坎坷,也不愿负年轻的胖胖,自学之路,共勉

猜你喜欢

转载自www.cnblogs.com/ruianShen/p/10121048.html