• org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)


    解决 :org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    1.问题分析:

    出现这种问题一般为两种情况:

    1. 检查mybatis 中xml文件里绑定的方法名字和mapper接口中的方法名字是否相同,以及xml中返回的类型路径是否正确;
    2. 第二种情况 是由于maven加载机制导致的:
      maven加载机制: 默认情况下,在src ->main ->java目录下面,maven只会加载java类型文件,其他类型文件不会加载的

    2.解决方式:

    1. 直接复制:将xml文件直接复制target文件里(不建议)。
    2. 在xml文件放到resources目录下 (这种方式改变了工程的目录结构)。
    3. 通过配置方式自动加载(建议方式)
      ① 在pom.xml 文件中添加
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
        <resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.ymlinclude>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
                <includes> <include>**/*.ymlinclude>
                    <include>**/*.propertiesinclude>
                    <include>**/*.xmlinclude>
                includes>
                <filtering>falsefiltering>
            resource>
        resources>
    build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    ②在application.properties文件中添加

    mybatis-plus.mapper-locations=classpath:com/atguigu/ggkt/vod/mapper/xml/*.xml
    
    • 1

    3.额外注意事项:(摘自csdn)

    不正确的配置

    mybatis-plus:
      mapper-locations: classpath*:mapper/*.xml,classpath:mapper/**/*Mapper.xml
    
    • 1
    • 2

    正确的配置

    mybatis-plus:
      mapper-locations: classpath*:mapper/*.xml,classpath*:mapper/**/*Mapper.xml
    
    
    • 1
    • 2
    • 3

    说明:classpath后的 * 不可缺少
    Idea启动不报错,使用 java -jar命令行运行就报错的话,网上是这么说的:

    classpath的使用:
    当项目中有多个classpath路径,并同时加载多个classpath路径下(此种情况多数不会遇到)的文件,就发挥了作用,如果不加,则表示仅仅加载第一个classpath路径
    classpath:只会到你的class路径中查找找文件;
    classpath
    :不仅包含class路径,还包括jar文件中(class路径)进行查找。

  • 相关阅读:
    luffy项目之后台项目搭建、目录调整、封装日志、全局异常、Response、数据库连接
    Dense embedding model 和 sparse embedding model 对比
    Vue中多条件图片路径通过Map存储获取避免嵌套if-else
    获取、设置注释的值
    数据血缘分析-Python代码的智能解析
    力扣刷题 day43:10-13
    【JUC的三个⼯具类】CountDownLatch 、CyclicBarrier 、Semaphore_JUC17
    360 评估反馈问题的示范案例
    【项目原理】ESP12F作无线网卡
    2024清理mac苹果电脑内存免费工具CleanMyMac X4.15
  • 原文地址:https://blog.csdn.net/qq_40084325/article/details/126276517