com.baomidou.mybatisplus.entity.GlobalConfiguration Java Examples

The following examples show how to use com.baomidou.mybatisplus.entity.GlobalConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlobalConfig.java    From mybatis-plus-sharding-jdbc-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
public GlobalConfiguration convertGlobalConfiguration() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    GlobalConfiguration globalConfiguration = new GlobalConfiguration();
    if (StringUtils.isNotEmpty(this.getIdentifierQuote())) {
        globalConfiguration.setIdentifierQuote(this.getIdentifierQuote());
    }
    if (StringUtils.isNotEmpty(this.getLogicDeleteValue())) {
        globalConfiguration.setLogicDeleteValue(this.getLogicDeleteValue());
    }
    if (StringUtils.isNotEmpty(this.getLogicNotDeleteValue())) {
        globalConfiguration.setLogicNotDeleteValue(this.getLogicNotDeleteValue());
    }
    if (StringUtils.isNotEmpty(this.getSqlInjector())) {
        globalConfiguration.setSqlInjector((ISqlInjector) Class.forName(this.getSqlInjector()).newInstance());
    }
    if (StringUtils.isNotEmpty(this.getMetaObjectHandler())) {
        globalConfiguration.setMetaObjectHandler((MetaObjectHandler) Class.forName(this.getMetaObjectHandler()).newInstance());
    }
    if (StringUtils.isNotEmpty(this.getKeyGenerator())) {
        globalConfiguration.setKeyGenerator((IKeyGenerator) Class.forName(this.getKeyGenerator()).newInstance());
    }
    if (StringUtils.checkValNotNull(this.getIdType())) {
        globalConfiguration.setIdType(this.getIdType());
    }
    if (null != this.getDbColumnUnderline()) {
        globalConfiguration.setDbColumnUnderline(this.getDbColumnUnderline());
    }
    if (StringUtils.checkValNotNull(this.getFieldStrategy())) {
        globalConfiguration.setFieldStrategy(this.getFieldStrategy());
    }
    if (StringUtils.checkValNotNull(this.getRefreshMapper())) {
        globalConfiguration.setRefresh(this.getRefreshMapper());
    }
    if (StringUtils.checkValNotNull(this.getCapitalMode())) {
        globalConfiguration.setCapitalMode(this.getCapitalMode());
    }
    if (null != this.getSqlParserCache()) {
        globalConfiguration.setSqlParserCache(this.getSqlParserCache());
    }
    return globalConfiguration;
}
 
Example #2
Source File: MybatisPlusConfig.java    From unimall with Apache License 2.0 4 votes vote down vote up
@Bean
public GlobalConfiguration globalConfiguration() {
    GlobalConfiguration conf = new GlobalConfiguration(new LogicSqlInjector());
    conf.setIdType(IdType.AUTO.getKey());
    return conf;
}
 
Example #3
Source File: MybatisPlusConfig.java    From watchdog-framework with MIT License 4 votes vote down vote up
/**
 * 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定
 * 配置文件和mybatis-boot的配置文件同步
 */
@Bean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() throws IOException {
    MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
    mybatisPlus.setDataSource(dataSource);
    mybatisPlus.setVfs(SpringBootVFS.class);
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    mybatisPlus.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    mybatisPlus.setConfiguration(properties.getConfiguration());
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        mybatisPlus.setPlugins(this.interceptors);
    }
    // MP 全局配置,更多内容进入类看注释
    GlobalConfiguration globalConfig = new GlobalConfiguration();
    globalConfig.setDbType(DBType.MYSQL.name());//数据库类型
    // ID 策略 AUTO->`0`("数据库ID自增") INPUT->`1`(用户输入ID") ID_WORKER->`2`("全局唯一ID") UUID->`3`("全局唯一ID")
    //使用ID_WORKER_STR,因为前后端分离使用整形,前端JS会有精度丢失
    globalConfig.setIdType(IdType.ID_WORKER_STR.getKey());
    globalConfig.setSqlInjector(new AutoSqlInjector());
    //MP 属性下划线 转 驼峰 , 如果原生配置 mc.setMapUnderscoreToCamelCase(true) 开启,该配置可以无。
    //globalConfig.setDbColumnUnderline(true);
    mybatisPlus.setGlobalConfig(globalConfig);
    MybatisConfiguration mc = new MybatisConfiguration();
    // 对于完全自定义的mapper需要加此项配置,才能实现下划线转驼峰
    mc.setMapUnderscoreToCamelCase(true);
    mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
    mybatisPlus.setConfiguration(mc);
    if (this.databaseIdProvider != null) {
        mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
    }
    return mybatisPlus;
}
 
Example #4
Source File: MybatisPlusConfig.java    From MI-S with MIT License 4 votes vote down vote up
/**
 * 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定
 * 配置文件和mybatis-boot的配置文件同步
 * @return
 */
@Bean
@ConditionalOnMissingBean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
    MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
    mybatisPlus.setDataSource(dataSource);
    mybatisPlus.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    mybatisPlus.setConfiguration(properties.getConfiguration());
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        mybatisPlus.setPlugins(this.interceptors);
    }
    // MP 全局配置,更多内容进入类看注释
    GlobalConfiguration globalConfig = new GlobalConfiguration();
    //驼峰下划线规则
    globalConfig.setDbColumnUnderline(true);
    globalConfig.setDbType(DBType.MYSQL.name());
    // ID 策略
    // AUTO->`0`("数据库ID自增")
    // INPUT->`1`(用户输入ID")
    // ID_WORKER->`2`("全局唯一ID")
    // UUID->`3`("全局唯一ID")
    globalConfig.setIdType(3);
    mybatisPlus.setGlobalConfig(globalConfig);
    MybatisConfiguration mc = new MybatisConfiguration();
    mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
    mybatisPlus.setConfiguration(mc);
    if (this.databaseIdProvider != null) {
        mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
    }
    return mybatisPlus;
}
 
Example #5
Source File: MybatisPlusConfig.java    From MI-S with MIT License 4 votes vote down vote up
/**
 * 这里全部使用mybatis-autoconfigure 已经自动加载的资源。不手动指定
 * 配置文件和mybatis-boot的配置文件同步
 * @return
 */
@Bean
@ConditionalOnMissingBean
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
    MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
    mybatisPlus.setDataSource(roundRobinDataSouceProxy());
    mybatisPlus.setVfs(SpringBootVFS.class);
    if (StringUtils.hasText(this.properties.getConfigLocation())) {
        mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
    }
    mybatisPlus.setConfiguration(properties.getConfiguration());
    if (!ObjectUtils.isEmpty(this.interceptors)) {
        mybatisPlus.setPlugins(this.interceptors);
    }
    // MP 全局配置,更多内容进入类看注释
    GlobalConfiguration globalConfig = new GlobalConfiguration();
    //驼峰下划线规则
    globalConfig.setDbColumnUnderline(true);
    globalConfig.setDbType(DBType.MYSQL.name());
    // ID 策略
    // AUTO->`0`("数据库ID自增")
    // INPUT->`1`(用户输入ID")
    // ID_WORKER->`2`("全局唯一ID")
    // UUID->`3`("全局唯一ID")
    globalConfig.setIdType(3);
    mybatisPlus.setGlobalConfig(globalConfig);
    MybatisConfiguration mc = new MybatisConfiguration();
    mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
    mybatisPlus.setConfiguration(mc);
    if (this.databaseIdProvider != null) {
        mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
    }
    if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
        mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
    }
    if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
        mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
    }
    if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
        mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
    }
    return mybatisPlus;
}
 
Example #6
Source File: DruidDataSourceConfig.java    From ssm-demo with MIT License 4 votes vote down vote up
public GlobalConfiguration globalConfigurationBean(){
    GlobalConfiguration globalConfiguration = new GlobalConfiguration();
    globalConfiguration.setIdType(2);//AUTO->`0`("数据库ID自增")、INPUT->`1`(用户输入ID")、ID_WORKER->`2`("全局唯一ID")、UUID->`3`("全局唯一ID")
    globalConfiguration.setDbColumnUnderline(true);//全局表为下划线命名设置 true
    return globalConfiguration;
}