• 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路径)进行查找。

  • 相关阅读:
    详细了解JVM运行时内存
    b站小土堆pytorch学习记录—— P17 土堆说卷积操作
    vue3自定义指令的学习和常用的几个自定义指令
    企业大数据分析的趋势是怎样
    C++中调用matplotlibcpp.h画图测试笔记
    JS——利用JS实现 tab 切换详解
    使用vpn/代理后电脑无法正常上网
    在预处理中用于预训练网络模型的均值和标准差的几种形式
    你好GPT-4o——对GPT-4o发布的思考与看法
    【深度学习】实验18 自然语言处理
  • 原文地址:https://blog.csdn.net/qq_40084325/article/details/126276517