|
|
|
@ -1,13 +1,22 @@
|
|
|
|
package cn.iocoder.yudao.framework.mybatis.config;
|
|
|
|
package cn.iocoder.yudao.framework.mybatis.config;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler;
|
|
|
|
import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.DbType;
|
|
|
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.incrementer.KingbaseKeyGenerator;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.incrementer.PostgreKeyGenerator;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* MyBaits 配置类
|
|
|
|
* MyBaits 配置类
|
|
|
|
@ -31,4 +40,25 @@ public class YudaoMybatisAutoConfiguration {
|
|
|
|
return new DefaultDBFieldHandler(); // 自动填充参数类
|
|
|
|
return new DefaultDBFieldHandler(); // 自动填充参数类
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
@ConditionalOnProperty(prefix = "mybatis-plus.global-config.db-config", name = "id-type", havingValue = "INPUT")
|
|
|
|
|
|
|
|
public IKeyGenerator keyGenerator(ConfigurableEnvironment environment) {
|
|
|
|
|
|
|
|
DbType dbType = IdTypeEnvironmentPostProcessor.getDbType(environment);
|
|
|
|
|
|
|
|
if (dbType != null) {
|
|
|
|
|
|
|
|
switch (dbType) {
|
|
|
|
|
|
|
|
case POSTGRE_SQL:
|
|
|
|
|
|
|
|
return new PostgreKeyGenerator();
|
|
|
|
|
|
|
|
case ORACLE:
|
|
|
|
|
|
|
|
case ORACLE_12C:
|
|
|
|
|
|
|
|
return new OracleKeyGenerator();
|
|
|
|
|
|
|
|
case H2:
|
|
|
|
|
|
|
|
return new H2KeyGenerator();
|
|
|
|
|
|
|
|
case KINGBASE_ES:
|
|
|
|
|
|
|
|
return new KingbaseKeyGenerator();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 找不到合适的 IKeyGenerator 实现类
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(StrUtil.format("DbType{} 找不到合适的 IKeyGenerator 实现类", dbType));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|