mybatis 中 多数据 map 结果集 转驼峰 返回null值 yml 设置方式

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();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值