开启驼峰命名的方法
第一种方式:
可以在配置类中进行配置。配置的Demo如下:
@Bean(name="sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setVfs(SpringBootVFS.class);
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
sqlSessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
//sqlSessionFactoryBean.setConfigLocation("mybatis-config.xml");
return sqlSessionFactoryBean.getObject();
}
第二种方式:
在SpringBoot的application配置文件中进行设置,这里是properties的配置,配置的Demo如下:
mybatis.configuration.mapUnderscoreToCamelCase=true 或 mybatis.configuration.map-underscore-to-camel-case=true
第三种方式:
第三种我称为原始的XML形式的配置,配置的Demo如下:
<?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="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>