SpringBoot集成Mybatis开启下划线格式的数据自动转换成小驼峰格式

SpringBoot集成Mybatis开启下划线格式的数据自动转换成小驼峰格式

本文是基于Java配置文件的

application.yml文件:

mybatis:
  configuration:
    map-underscore-to-camel-case: true

Java配置文件:

@MapperScan(basePackages = "com.abc.dao")
@org.springframework.context.annotation.Configuration
public class MybatisConfig {

    /**
     * 配置驼峰命名法等
     * @return
     */
    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return (Configuration configuration) -> configuration.setMapUnderscoreToCamelCase(true);
    }
	
    @Bean(name="sqlSessionFactory")
    public SqlSessionFactory sqlSessionFactory(@Qualifier("druidDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        sqlSessionFactoryBean.setVfs(SpringBootVFS.class);
        sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
        return sqlSessionFactoryBean.getObject();
    }
}

起作用的命令:

sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);

你可能感兴趣的:(SpringBoot)