MyBatis 配置详解

在项目中经常会用到 mybatis 相关的一些配置,而在启动类项目工程中,一般会把 mybatis 配置文件单独写到 mybatis,yml 中,如下简单介绍下常用的 mybatis 配置

yaml 复制代码
mybatis:
  configuration:
    call-setters-on-nulls: true
    map-underscore-to-camel-case: true
  mapperLocations: classpath*:mybatis/*.xml,classpath*:mapper/*.xml,classpath*:mybatis/mapping/**/*.xml,mybatis/base/*.xml

1、mybatis.configuration.call-setters-on-nulls: true

当查询结果中的字段值为 null 时,是否调用实体类对应属性的 setter 方法。设置为 true 时,即使字段值为 null,也会调用 setter 方法

2、mybatis.configuration.map-underscore-to-camel-case: true

将数据库字段名的下划线风格(如 user_name)映射为 Java 实体类的驼峰命名风格(如 userName)。设置为 true 时,MyBatis 会自动进行这种映射

3、mybatis.mapperLocations

指定了 MyBatis 映射文件(Mapper XML 文件)的路径。多个路径之间用逗号分隔,支持通配符 ***。具体路径说明如下:

yaml 复制代码
classpath*:mybatis/*.xml:扫描 classpath 下 mybatis 目录中的所有 .xml 文件
classpath*:mapper/*.xml:扫描 classpath 下 mapper 目录中的所有 .xml 文件
classpath*:mybatis/mapping/**/*.xml:扫描 classpath 下 mybatis/mapping 目录及其子目录中的所有 .xml 文件
mybatis/base/*.xml:扫描 mybatis/base 目录中的所有 .xml 文件
相关推荐
Java内核笔记2 分钟前
万字避坑!Spring Boot 3.x 升 4.0 最全升级指南(附 Migration Checklist,建议收藏⭐)
java·后端
cfm_29141 小时前
SpringBoot启动原理
java·spring boot·spring
漫随流水2 小时前
Java——springboot web案例
java·开发语言·spring boot
从此以后自律2 小时前
Java Object 类常用方法全讲解
java·开发语言
念何架构之路2 小时前
Docker 容器状态机 学习
java·学习·docker
你有我备注吗2 小时前
SQL学习之查询
java·sql·学习
xixi09243 小时前
JMeter5.6.3基础使用教程1
java·开发语言
带刺的坐椅3 小时前
用 Solon ReActAgent 落地发票识别与智能报销
java·llm·solon·react-agent
罗超驿3 小时前
15.Java异常处理:从束手无策到从容应对
java·开发语言
Co_Hui3 小时前
Java 基础
java·开发语言