mapper-locations: classpath:mapper/*.xml配置是必须的吗 不是必须的但要根据你的使用场景来决定是否需要。什么时候可以不配置mapper-locations如果你只使用 MyBatis-Plus 的注解方式编写 SQL如Select、Insert、Update、Delete并且不需要 XML 文件那么mapper-locations配置完全可以省略。示例只使用注解javaMapper public interface DriverInfoMapper extends BaseMapperDriverInfo { // 使用注解方式编写 SQL Select(SELECT * FROM driver_info WHERE driver_no #{driverNo}) DriverInfo selectByDriverNo(String driverNo); Insert(INSERT INTO driver_info (driver_name, driver_no, age) VALUES (#{driverName}, #{driverNo}, #{age})) int insertDriver(DriverInfo driver); }这种情况下不需要配置mapper-locations。什么时候必须配置mapper-locations当你需要使用 XML 文件来编写复杂 SQL 时就必须配置mapper-locations让 MyBatis-Plus 知道去哪里加载这些 XML 文件。示例使用 XML 文件xml!-- src/main/resources/mapper/DriverInfoMapper.xml -- ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.seazon.cloud.mapper.DriverInfoMapper !-- 复杂查询多表关联、动态条件等 -- select idselectByCondition resultTypecom.seazon.cloud.entity.DriverInfo SELECT * FROM driver_info where if testdriverName ! null and driverName ! AND driver_name LIKE CONCAT(%, #{driverName}, %) /if if testage ! null AND age #{age} /if /where /select /mapperjavaMapper public interface DriverInfoMapper extends BaseMapperDriverInfo { // XML 中定义的方法 ListDriverInfo selectByCondition(Param(driverName) String driverName, Param(age) Integer age); }这时必须在配置文件中指定 XML 位置yamlmybatis-plus: mapper-locations: classpath:mapper/*.xml默认值如果你不配置mapper-locationsMyBatis-Plus 的默认值是textclasspath*:/mapper/**/*.xml也就是说即使你不配置只要你的 XML 文件放在src/main/resources/mapper/目录下或任意子目录下MyBatis-Plus 也会自动扫描到。对比总结场景是否必须配置mapper-locations说明只用注解Select等❌ 不需要XML 文件根本不存在用 XML 文件放在resources/mapper/下❌ 不需要配置使用默认值即可用 XML 文件放在其他位置✅ 必须配置例如classpath:mybatis/xml/*.xml同时使用注解 XML看 XML 位置同上分页插件等高级功能❌ 不需要分页插件不依赖 XML建议如果你不确定将来是否会用 XML可以保留配置不影响启动yamlmybatis-plus: mapper-locations: classpath:mapper/*.xml如果你确定只使用注解方式可以省略yamlmybatis-plus: # 不需要配置 mapper-locations global-config: db-config: id-type: auto configuration: map-underscore-to-camel-case: true log-impl: org.apache.ibatis.logging.stdout.StdOutImpl现在你的项目已经配置好了 MyBatis-Plus可以开始写代码了

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/9/25 12:45:43
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/24 14:25:52
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/26 3:42:08
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/9/23 8:01:38
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/26 4:08:27
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/25 15:49:36

日新闻

周新闻