org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的三种解决方式

在使用mybatis-plus自定义SQL的时候,没有使用注解方式,而是将SQL语句写在mappper.xml文件中,就报了这个错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 说某个方法没找到。

原因:maven默认加载机制,只会把src/main/java文件夹中的java类型文件进行加载,其他类型文件不会加载

解决方式:

方式一:手动复制xml文件到target目录

在这里插入图片描述

方式二:将xml文件放到resources目录下

注意:xml目录放到resources目录后,mapper目录下的xml目录就不需要了,记得删除。
在这里插入图片描述

方式三:通过配置文件

1、在pom文件中添加如下代码:将xml也打包到项目中

<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

2、在properties配置文件中添加如下配置

#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml

你更喜欢哪一种解决方式呢?