MyBatis 配置详解

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

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 文件)的路径。多个路径之间用逗号分隔,支持通配符 ***。具体路径说明如下:

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 文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兮动人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值