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 文件
相关推荐
admiraldeworm1 小时前
Spring Boot + Spring AI 最小可运行 Demo
java·人工智能·ai
chenglin0161 小时前
ES_数据存储知识
java·服务器·elasticsearch
fs哆哆2 小时前
在VB.net中一维数组,与VBA有什么区别
java·开发语言·数据结构·算法·.net
johnZhangqi2 小时前
深圳大学-计算机信息管理课程实验 C++ 自考模拟题
java·开发语言·c++
David爱编程2 小时前
并发编程三大特性全解析:原子性、可见性、有序性,一文讲透!
java·后端
Sally璐璐2 小时前
Go语言变量声明与初始化详解
java·开发语言·golang
C4程序员3 小时前
北京JAVA基础面试30天打卡14
java·开发语言·面试
LGL6030A4 小时前
Java学习历程14——制作一款五子棋游戏(4)
java
qq_589568106 小时前
javaweb开发笔记—— 前端工程化
java·前端
码农小灰6 小时前
Kafka消息持久化机制全解析:存储原理与实战场景
java·分布式·kafka