第一种
properties配置
mybatis.configuration.mapUnderscoreToCamelCase = true
@Bean
@ConfigurationProperties(prefix = “mybatis.configuration”)
public org.apache.ibatis.session.Configuration globalConfiguration(){
return new org.apache.ibatis.session.Configuration();
}
@Bean(name = "mysqlSqlSessionFactory")
@Primary
public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource,org.apache.ibatis.session.Configuration config) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setConfiguration(config);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mysql-mapper/*Mapper.xml"));
return bean.getObject();
}
第二种
@Bean(name = “mysqlSqlSessionFactory”)
@Primary
public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier(“mysqlDataSource”) DataSource dataSource,org.apache.ibatis.session.Configuration config) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(“classpath:mysql-mapper/*Mapper.xml”));
bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
return bean.getObject();
}