mybatis:
mapper-locations: classpath:/mapper/*Dao.xml
configuration:
call-setters-on-nulls: true
map-underscore-to-camel-case: true
object-wrapper-factory: com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory
// 报错问题后 加入如下配置
package com.clear.tracesource.common.db.config;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
@ConfigurationPropertiesBinding
public class ObjectWrapperFactoryConverter implements Converter<String,ObjectWrapperFactory> {
@Override
public ObjectWrapperFactory convert(String source) {
try {
return (ObjectWrapperFactory) Class.forName(source).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
// 因为多数据源,yml中的配置会不生效,需要加入如下配置
@Bean()
@ConfigurationProperties(prefix = "mybatis.configuration")
public org.apache.ibatis.session.Configuration configuration(){
return new org.apache.ibatis.session.Configuration();
}
@Bean(name = "sessionFactory")
public SqlSessionFactory sessionFactory(@Qualifier("dynamicDataSource") DataSource dataSource, org.apache.ibatis.session.Configuration configuration) throws Exception {
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//*Mapper.xml位置
sessionFactoryBean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
sessionFactoryBean.setConfiguration(configuration);
return sessionFactoryBean.getObject();
}
mybatis 中 多数据 map 结果集 转驼峰 返回null值 yml 设置方式
最新推荐文章于 2023-02-15 11:43:22 发布