🎈个人公众号:🎈 :✨✨ 可为编程 ✨✨ 🍟🍟
🔑个人信条:🔑知足知不足 有为有不为 为与不为皆为可为🌵
🍉本篇简介:🍉 本片详细说明了解决SpringBoot获取mapper.xml路径的问题,并给出具体操作实例,如有出入还望指正。
当mapper.xml与mapper.class放在同一文件夹下时,是不能够将xml文件打包进项目的,项目构建的时候不会加载到target文件夹中。在pom.xml中加入如下这句:
<!--;这个元素描述了项目相关的所有资源路径列表,例如和项目相关的属性文件,这些资源被包含在最终的打包文件里。-->
<resources>
<resource>
<!--描述存放资源的目录,该路径相对POM路径-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
如果mapper.xml文件放在resources下面得mapper文件中,就需要在application.properties中加上
mybatis.mapper-locations=classpath:**/*.xml
或者是
mybatis.mapper-locations=classpath:mapper/*.xml
在application.yum文件夹中配置如下:
mybatis:
mapper-locations: classpath:** /*.xml # mapper映射文件路径
或者
mybatis:
mapper-locations: classpath:mapper/*.xml