Mybatis-plus常用进阶配置

1.mapUnderscoreToCamelCase

是否开启自动驼峰命名规则(camel case)映射,即从经典数据库列名 A_COLUMN(下划线命名) 到经典 Java 属性名 aColumn(驼峰命名) 的类似映射。

注意 此属性在 MyBatis 中原默认值为 false,在 MyBatis-Plus 中,此属性也将用于生成最终的 SQL 的 select body 如果您的数据库命名符合规则无需使用 @TableField 注解指定数据库字段名

SpringBoot配置

#关闭自动驼峰映射,该参数不能和mybatis-plus.config-location同时存在 
mybatis-plus.configuration.map-underscore-to-camel-case=false

2.cacheEnabled

全局地开启或关闭配置文件中的所有映射器已经配置的任何缓存,默认为 true。 # callSettersOnNulls

SpringBoot配置

mybatis-plus.configuration.cache-enabled=false

3.DbConfig

1.idType

SpringBoot:

mybatis-plus.global-config.db-config.id-type=auto

SpringMVC

<!--这里使用MP提供的sqlSessionFactory,完成了Spring与MP的整合-->    
<bean id="sqlSessionFactory"  class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">        
<property name="dataSource" ref="dataSource"/>        
<property name="globalConfig">            
<bean class="com.baomidou.mybatisplus.core.config.GlobalConfig">                
<property name="dbConfig">                    
<bean class="com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig">                        <property name="idType" value="AUTO"/> </bean>                   
               
  </property>           
   </bean>       
    </property>    
    </bean>

2.tablePrefix

  • 类型:String
  • 默认值:null
  • 表名前缀

SpringBoot:

mybatis-plus.global-config.db-config.table-prefix=tb_

SpringMVC

<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="globalConfig">
    <bean class="com.baomidou.mybatisplus.core.config.GlobalConfig">
        <property name="dbConfig">
            <bean class="com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig">
                <property name="idType" value="AUTO"/>
                <property name="tablePrefix" value="tb_"/>
            </bean>
        </property>
    </bean>
</property>
</bean>
发布了18 篇原创文章 · 获赞 4 · 访问量 1071

猜你喜欢

转载自blog.csdn.net/weixin_44689277/article/details/104407221