Mybatis配置(部分)说明

说明:以下配置为在项目中已使用的 # MyBatis配置 (当前配置在application.yml中) mybatis: typeAliasesPackage: com.project.**.domain mapperLocations: classpath*:mapper/**/*Mapper.xml configLocation: classpath:mapper/mybatis-config.xml #configuration: #map-underscore-to-camel-case: true

使用:

1、typeAliasesPackage:搜索指定包别名

设置前:parameterMap=“com.project.my.domain.Test”;

设置后:parameterMap=“Test”;

2、mapperLocations:配置mapper的扫描,找到所有的mapper.xml映射文件

3、configLocation:加载全局的配置文件

4、configuration:配置(也可以配置在mybatis-config.xml中)

例:mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
   <settings>
      <setting name="cacheEnabled"             value="true"  />  <!-- 全局映射器启用缓存 -->
      <setting name="useGeneratedKeys"         value="false" />  <!-- 允许 JDBC 支持自动生成主键 -->
      <setting name="defaultExecutorType"      value="REUSE" /> <!-- 配置默认的执行器 -->
      <setting name="logImpl"                  value="SLF4J" /> <!-- 指定 MyBatis 所用日志的具体实现 -->
      <setting name="mapUnderscoreToCamelCase" value="true"/>  <!--驼峰式命名 -->
   </settings>
</configuration>

5、map-underscore-to-camel-case :驼峰命名规则自动转换

经验分享 程序员 微信小程序 职场和发展