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;
}
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);
}
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();
}
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);
}
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();
}
Aggregations