SpringBoot开启驼峰映射

一 、application.yml配置

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

二、光这样配置你会发现mapper的驼峰映射并未起作用,需要在DataSource配置类添加下方划线标志的代码

 
  
@Bean(name="config")
@ConfigurationProperties(prefix = "mybatis.configuration")
public org.apache.ibatis.session.Configuration mybatiesConfig(){ 
   return new org.apache.ibatis.session.Configuration();}
 
   
@Bean(name = "campaignsSqlSessionFactory")
public SqlSessionFactory campaignsSqlSessionFactory(
@Qualifier( "campaignsDataSource") DataSource campaignsDataSource,
org.apache.ibatis.session.Configuration config) throws Exception {
final SqlSessionFactoryBean sqlSessionFactoryBean =
new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(campaignsDataSource);
Resource[] mapperLocations = new
PathMatchingResourcePatternResolver().getResources(CampaignsConfig. MAPPER_LOCATION); sqlSessionFactoryBean.setMapperLocations(mapperLocations);
sqlSessionFactoryBean.setTypeAliasesPackage( TYPE_ALIASES_PACKAGE);
sqlSessionFactoryBean.setConfiguration(config);
return sqlSessionFactoryBean.getObject();}

三、或者在mapper.xml文件中使用resultMap也可实现手动设置的映射

<resultMap type="com.nttdata.dm30.club.admin.model.entity.bbs.YJHAutoRewardLog" id="youjuhuilogMap">
    <result property="logId" column="log_id"/>
    <result property="logDetail" column="log_detail"/>
    <result property="logTime" column="log_time"/>
    <result property="logStatus" column="log_status"/>
resultMap>

你可能感兴趣的:(SpringBoot开启驼峰映射)