mybatis 配置了驼峰映射,映射不上

mybatis:
  typeAliasesPackage: com.gaia.order.vo,com.gaia.order.model
  configuration:
        map-underscore-to-camel-case: true
  mapper-locations: classpath:com/gaia/pay/mapping/**/*.xml

主要是因为配置的是2个数据库,导致映射不上。需要修改Dbconfig

package com.gaia.pay.config;

import com.gaia.pay.config.datasource.DynamicDataSource;
import com.gaia.pay.config.datasource.DynamicDataSourceTransactionManager;
import com.gaia.pay.config.datasource.DynamicPlugin;
import com.gaia.pay.config.db.DBProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: jiangsai
 * Date: 2018-12-26
 * Time: 12:02 PM
 */
@Configuration
@ConfigurationProperties(prefix = "mybatis")
@Slf4j
public class DataSourceConfig {

    @Resource
    private DBProperties properties;

    private String mapperLocations;

    private String typeAliasesPackage;

    @Bean
    public DataSource dataSource() {
        DynamicDataSource dataSource = new DynamicDataSource();
        dataSource.setMasterDataSource(properties.getMaster());
        dataSource.setSlaveDataSource(properties.getSlave());
        log.info("Master JdbcUrl: {}", properties.getMaster().getJdbcUrl());
        log.info("Slave JdbcUrl: {}", properties.getSlave().getJdbcUrl());
        return dataSource;
    }

    @Bean
    @ConfigurationProperties(prefix = "mybatis.configuration")
    public org.apache.ibatis.session.Configuration configuration() {
        return new org.apache.ibatis.session.Configuration();
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory(org.apache.ibatis.session.Configuration configuration) throws Exception {
        SqlSessionFactoryBean fb = new SqlSessionFactoryBean();
        fb.setDataSource(dataSource());
        fb.setMapperLocations(new PathMatchingResourcePatternResolver()
                .getResources(mapperLocations));
        fb.setTypeAliasesPackage((typeAliasesPackage));
        Interceptor[] plugins = { new DynamicPlugin() };
        fb.setPlugins(plugins);
        fb.setConfiguration(configuration);
        return fb.getObject();
    }

    @Bean
    public DataSourceTransactionManager transactionManager() {
        DynamicDataSourceTransactionManager m = new DynamicDataSourceTransactionManager();
        m.setDataSource(dataSource());
        return m;
    }

    public String getMapperLocations() {
        return mapperLocations;
    }

    public void setMapperLocations(String mapperLocations) {
        this.mapperLocations = mapperLocations;
    }

    public String getTypeAliasesPackage() {
        return typeAliasesPackage;
    }

    public void setTypeAliasesPackage(String typeAliasesPackage) {
        this.typeAliasesPackage = typeAliasesPackage;
    }

}

mybatis 配置了驼峰映射,映射不上_第1张图片

主动添加驼峰映射

你可能感兴趣的:(mybatis)