Search in sources :

Example 6 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project citrus by Yiuman.

the class DynamicDataSourceAutoConfiguration method getCopyMybatisConfiguration.

private MybatisConfiguration getCopyMybatisConfiguration(MybatisPlusProperties mybatisPlusProperties) {
    MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
    // 如果配置中有,则拷贝一份
    Optional.ofNullable(mybatisPlusProperties.getConfiguration()).ifPresent(propertiesConfiguration -> BeanUtils.copyProperties(propertiesConfiguration, mybatisConfiguration));
    if (!CollectionUtils.isEmpty(this.configurationCustomizers)) {
        for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
            customizer.customize(mybatisConfiguration);
        }
    }
    return mybatisConfiguration;
}
Also used : MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration)

Example 7 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project mybatis-plus-samples by baomidou.

the class NoSpring method initSqlSessionFactory.

public static SqlSessionFactory initSqlSessionFactory() {
    DataSource dataSource = dataSource();
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    MybatisConfiguration configuration = new MybatisConfiguration(environment);
    configuration.addMapper(PersonMapper.class);
    configuration.setLogImpl(StdOutImpl.class);
    return new MybatisSqlSessionFactoryBuilder().build(configuration);
}
Also used : MybatisSqlSessionFactoryBuilder(com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource)

Example 8 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project mybatis-plus-samples by baomidou.

the class MybatisPlusConfig method sqlSessionFactory.

@Bean("mybatisSqlSession")
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, GlobalConfig globalConfig) throws Exception {
    MybatisSqlSessionFactoryBean sqlSessionFactory = new MybatisSqlSessionFactoryBean();
    /* 数据源 */
    sqlSessionFactory.setDataSource(dataSource);
    /* 枚举扫描 */
    sqlSessionFactory.setTypeEnumsPackage("com.baomidou.mybatisplus.samples.mysql.enums");
    /* xml扫描 */
    sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/mapper/*.xml"));
    /* 扫描 typeHandler */
    // sqlSessionFactory.setTypeHandlersPackage("com.baomidou.mybatisplus.samples.mysql.type");
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    /* 驼峰转下划线 */
    configuration.setMapUnderscoreToCamelCase(true);
    MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
    mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
    mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
    sqlSessionFactory.setPlugins(mybatisPlusInterceptor);
    /* map 下划线转驼峰 */
    configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
    sqlSessionFactory.setConfiguration(configuration);
    /* 自动填充插件 */
    globalConfig.setMetaObjectHandler(new MysqlMetaObjectHandler());
    sqlSessionFactory.setGlobalConfig(globalConfig);
    return sqlSessionFactory.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisMapWrapperFactory(com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory) OptimisticLockerInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project albedo by somowhere.

the class BaseDatabaseConfiguration method applyConfiguration.

protected void applyConfiguration(MybatisSqlSessionFactoryBean factory) {
    MybatisConfiguration newConfiguration = this.properties.getConfiguration();
    if (newConfiguration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
        newConfiguration = new MybatisConfiguration();
    }
    // somewhere 改过这里:  这里一定要复制一次, 否则多数据源时,会导致拦截器等执行多次
    MybatisConfiguration configuration = new MybatisConfiguration();
    BeanUtil.copyProperties(newConfiguration, configuration);
    configuration.getTypeHandlerRegistry().setDefaultEnumTypeHandler(CustomEnumTypeHandler.class);
    if (!CollectionUtils.isEmpty(this.configurationCustomizers)) {
        for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
            customizer.customize(configuration);
        }
    }
    factory.setConfiguration(configuration);
}
Also used : ConfigurationCustomizer(com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration)

Example 10 with MybatisConfiguration

use of com.baomidou.mybatisplus.core.MybatisConfiguration in project zhili-dataplatform by javasqlbug.

the class SpringConnectionFactory method sqlSessionFactory.

/**
 * * get sql session factory
 *
 * @return sqlSessionFactory
 * @throws Exception sqlSessionFactory exception
 */
@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setMapUnderscoreToCamelCase(true);
    configuration.setCacheEnabled(false);
    configuration.setCallSettersOnNulls(true);
    configuration.setJdbcTypeForNull(JdbcType.NULL);
    configuration.addInterceptor(paginationInterceptor());
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfiguration(configuration);
    sqlSessionFactoryBean.setDataSource(dataSource());
    GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
    dbConfig.setIdType(IdType.AUTO);
    GlobalConfig globalConfig = new GlobalConfig();
    globalConfig.setDbConfig(dbConfig);
    sqlSessionFactoryBean.setGlobalConfig(globalConfig);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.niezhili.dataplatform.report.dao.entity");
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("com/niezhili/dataplatform/monitor/dao/mapper/*Mapper.xml"));
    sqlSessionFactoryBean.setTypeEnumsPackage("com.niezhili.dataplatform.report.dao.*.enums");
    sqlSessionFactoryBean.setDatabaseIdProvider(databaseIdProvider());
    return sqlSessionFactoryBean.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) GlobalConfig(com.baomidou.mybatisplus.core.config.GlobalConfig) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)17 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)12 Bean (org.springframework.context.annotation.Bean)10 GlobalConfig (com.baomidou.mybatisplus.core.config.GlobalConfig)9 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)7 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)4 ConfigurationCustomizer (com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer)3 MybatisPlusProperties (com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties)2 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)2 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)2 Environment (org.apache.ibatis.mapping.Environment)2 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)2 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)2 MybatisSqlSessionFactoryBuilder (com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder)1 MybatisMapWrapperFactory (com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory)1 PaginationInterceptor (com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)1 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)1 DataSource (javax.sql.DataSource)1 Primary (org.springframework.context.annotation.Primary)1 Resource (org.springframework.core.io.Resource)1