报错现象

原因
mapper 实例对象对应的 mapper.xml 未找到
解决方案
启动类扫描未扫到 mapper 层
@SpringBootApplication
@MapperScan("路径.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args);
}
}
如果代码注入了 mapper 层,则启动会直接报错
mapper 和 xml 绑定路径出错
检查 mapper 是否可以点击跳转到 xml 文件。需要插件 mybatis x
mapper-locations 指定位置有误
- 默认值:
["classpath*:/mapper/**/*.xml"]
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
mapper.xml 未放到指定的 resource 文件中
方法一:移动 xml 文件到 resource/mapper 目录下
方法二:java 目录下代码编译包含 xml 文件。默认只编译 java 文件
指定 POM 文件的 resource
<build>
<resources>
<resource>
<!-- xml放在java目录下-->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<!--指定资源的位置(xml放在resources下,可以不用指定)-->
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
上面官网搜索 自定义 SQL 无法执行
参考
Maven学习笔记(十二)-maven打包之resource配置_resource targetpath-优快云博客
【.xml文件匹配不到】⭐️解决使用mybatis-plus找不到对应的xml文件导致的持久层方法报错_mybatisplus 找不到 resource 下的 xml文件-优快云博客
SpringBoot:Invalid bound statement (not found)的原因和解决方案-优快云博客
mybatis-plus的 mapper.xml 路径配置的坑_51CTO博客_mybatis-plus.mapper-locations

1547

被折叠的 条评论
为什么被折叠?



