• springboot


    以前都是在mybatis.xml中来配置,但是spring boot不想再用xml配置文件。网上搜寻了好久,才找到设置办法:sessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);

    db配置文件源码:

    package com.vip.qa.vop.config;
    
    import com.alibaba.druid.pool.DruidDataSource;
    import org.apache.ibatis.session.SqlSessionFactory;
    import org.mybatis.spring.SqlSessionFactoryBean;
    import org.mybatis.spring.annotation.MapperScan;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;
    import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
    import org.springframework.jdbc.datasource.DataSourceTransactionManager;
    import javax.sql.DataSource;
    import java.util.Properties;
    
    /**
     * Created by danny.yao on 2017/10/25.
     */
    @Configuration
    @MapperScan(basePackages = VOPDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "vopSqlSessionFactory")
    public class VOPDataSourceConfig {
        static final String PACKAGE = "com.vip.qa.vop.mapper.vop";
    
        @Value("${vop.datasource.url}")
        private String dbUrl;
    
        @Value("${vop.datasource.username}")
        private String dbUser;
    
        @Value("${vop.datasource.password}")
        private String dbPassword;
    
        @Value("${vop.datasource.driver-class-name}")
        private String dbDriver;
    
        @Bean(name = "vopDataSource")
        @Qualifier
        @Primary
        public DataSource vopDataSource() {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setDriverClassName(dbDriver);
            dataSource.setUrl(dbUrl);
            dataSource.setUsername(dbUser);
            dataSource.setPassword(dbPassword);
            return dataSource;
        }
    
        @Bean(name = "vopSqlSessionFactory")
        @Qualifier
        @Primary
        public SqlSessionFactory vopSqlSessionFactory(@Qualifier("vopDataSource") DataSource scepDataSource) throws Exception {
            final SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
            sessionFactoryBean.setDataSource(scepDataSource);
    
            PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            sessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/vop/*.xml"));
            sessionFactoryBean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
    
            return sessionFactoryBean.getObject();
        }
    
    //    @Bean(name = "vopTransactionManager")
    //    @Qualifier
    //    public DataSourceTransactionManager testDataTransactionManager() {
    //        return new DataSourceTransactionManager(vopDataSource());
    //    }
    
    }

    参考:http://www.cnblogs.com/gods/p/4423422.html



  • 相关阅读:
    转:10分钟掌握XML、JSON及其解析
    转:关于C++14:你需要知道的新特性
    2014/11/4~2014/12/20阶段性目标
    转:快速掌握一个语言最常用的50%
    推荐!国外程序员整理的 C++ 资源大全
    数据库面试宝典
    sqlite学习
    android
    转:c的回归-云风
    原创: 开题报告中摘要部分快速将一段文字插入到word的表格中
  • 原文地址:https://www.cnblogs.com/dannyyao/p/7736246.html
Copyright © 2020-2023  润新知