The configuration of MybatisPlus

Before the order

MybatisPlus general CRUD interface MybatisPlus conditional constructor MybatisPlus code generator tutorial details The configuration of MybatisPlus

There are a number of configurations in Mybatis-Plus, some of which belong to Mybatis and some of which belong to Mybatis-Plus. Simple record of Mybatis-Plus common configuration

The basic configuration

configLocation

  • Type: String

  • Default value: null

MyBatis configuration file location. If you need to set a separate MyBatis configuration, configure its path to configLocation. For details about Configuration, see the Official documentation of MyBatis

  • Spring Boot
mybatis-plus.config-location = classpath:mybatis-config.xml
Copy the code
  • Spring MVC
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
Copy the code

mapperLocations

  • Type: String []

  • Default value: [“classpath*:/mapper/**/*.xml”]

If you have custom methods in Mapper (custom implementation in XML), this configuration is required to tell Mapper the location of the corresponding XML file.

WARNING Maven multi-module project scan path must start with classpath*:

  • Spring Boot
mybatis-plus.mapper-locations = classpath*:mybatis/*.xml
Copy the code
  • Spring MVC
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
    <property name="mapperLocations" value="classpath*:mybatis/*.xml"/>
</bean>
Copy the code

typeAliasesPackage

  • Type: String

  • Default value: null

MyBaits alias package scan path, through this attribute can be registered to the package class alias, after registration in Mapper corresponding XML file can directly use the class name, instead of using the fully qualified class name (that is, XML calls do not contain the package name).

  • Spring Boot
mybatis-plus.type-aliases-package = com.mybatis.mp.pojo
Copy the code
  • Spring MVC
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
    <property name="typeAliasesPackage" value="com.baomidou.mybatisplus.samples.quickstart.entity"/>
</bean>
Copy the code

The advanced configuration

mapUnderscoreToCamelCase

  • Type:boolean
  • Default value:true

Whether to enable automatic Camel Case mapping from the classic database column name A_COLUMN (underlined name) to the classic Java property name aColumn (camel name).

Pay attention to

This property defaults to false in MyBatis and will also be used to generate the select body of the final SQL in MyBatis-Plus

There is no need to specify database field names using the @TableField annotation if your database is named according to the rules

  • SpringBoot
This parameter cannot be used with mybatis-plus.config-location
mybatis-plus.configuration.map-underscore-to-camel-case=false
Copy the code

cacheEnabled

  • Type:boolean
  • Default value:true

Globally turn on or off any caches that have been configured by all mappers in the configuration file, default to true.

  • SpringBoot
mybatis-plus.configuration.cache-enabled=false
Copy the code