mybatis报错:Invalid bound statement (not found)的原因很多,但是正如报错提示一样,找不到xml中的sql语句,报错的情况分为三种:
第一种:语法错误
Java DAO层接口
public void delete(@Param("id")String id);Java 对应的mapper.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xxx.xxx.xxx.Mapper">
    <!-- 删除数据 -->
    <delete id="delete" parameterType="java.lang.String">
        DELETE FROM xxx WHERE id=#{id}
    </delete>
</mapper>检查:
- 接口中方法名(delete)与xml文件中 id="delete"是否一致
- xml文件中的 namespace="xxx.xxx.xxx.Mapper"中的路径是否与接口文件路径一致
- parameterType类型 与 resultType类型是否准确;resultMap与resultType是不一样的。
第二种:编译错误
定位到项目路径下:target\classes\ 中报错路径下,寻找对应的xml文件是否存在。
(1)、若不存在对应的xml文件,则需要在pom.xml中加入以下代码:
<build>
    <resources>
         <resource>
             <directory>src/main/java</directory>
             <excludes>
                 <exclude>**/*.java</exclude>
             </excludes>
         </resource>
         <resource>
             <directory>src/main/resources</directory>
             <includes>
                 <include>**/*.*</include>
             </includes>
        </resource>
    </resources>
</build>删除classes文件夹中文件,重新编译,出现了对应的xml文件即可。
(2)、若存在xml文件,则打开xml文件,检查其中报错部分是否与源文件一致,不一致,则:
   先清除classes文件夹中文件,执行命令:mvn clean 清理内容,重新编译后即可。
第三种:配置错误
(1)在配置文件中指定扫描包时,配置路径有问题。
例如:spring配置文件中”basePackage” 属性包名的指定一定要具体到接口所在包,而不要写父级甚至更高级别的包 ,否则可能出现问题;cn.dao 与cn.*也可能导致错误;注解扫描时,可能没有扫描到包等。
(2)yaml配置错误
如果在resource下面,加了字包,需要在配置文件里面使用层级通配符处理,否则项目启动的时候只能parse第一级目录下的xml文件,子层级的文件无法parse。
正确配置

mybatis-plus:
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: /mapper/**/*.xml #统配符号表示由层级关系错误配置

mybatis-plus:
  configuration:
    map-underscore-to-camel-case: true
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: /mapper/*.xml以下上的配置只能parse mapper包下的xml文件,无法parse target包下面的xml文件,导致在调用mapper中的方法查询的时候就报报错:Invalid bound statement (not found)



















