自学内容网 自学内容网

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 文件

原文地址:https://blog.csdn.net/qq_41684621/article/details/143059148

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!