版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lsy1072/article/details/79318660
通常在使用MyBatis时我们会吧映射文件如UserMapping.xml放在源码中,但是在Maven中编译后不会自动把xml文件复制到classes文件中,所以需要手动在pom.xml中设置
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
还有另外一种解决方法,就是将映射文件放在resources/sqlmapping文件夹下,然后在mybatis-config.xml中进行如下导入:
<mappers>
<mapper resource="sqlmapping/UserMapper.xml"/>
</mappers>