Pre Merge pull request !208 from 墨轩/master
commit
96fc13ea6e
|
|
@ -9,7 +9,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.MapPropertySource;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,11 +59,23 @@ public class IdTypeEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdType getIdType(ConfigurableEnvironment environment) {
|
public IdType getIdType(ConfigurableEnvironment environment) {
|
||||||
return environment.getProperty(ID_TYPE_KEY, IdType.class);
|
// return environment.getProperty(ID_TYPE_KEY, IdType.class);
|
||||||
|
String value = environment.getProperty(ID_TYPE_KEY);
|
||||||
|
try {
|
||||||
|
return StrUtil.isNotBlank(value) ? IdType.valueOf(value) : IdType.NONE;
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
log.error("无法解析 id-type 配置值:{}", value, ex);
|
||||||
|
return IdType.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdType(ConfigurableEnvironment environment, IdType idType) {
|
public void setIdType(ConfigurableEnvironment environment, IdType idType) {
|
||||||
environment.getSystemProperties().put(ID_TYPE_KEY, idType);
|
// environment.getSystemProperties().put(ID_TYPE_KEY, idType);
|
||||||
|
// log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType);
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put(ID_TYPE_KEY, idType);
|
||||||
|
environment.getPropertySources().addFirst(new MapPropertySource("mybatisPlusIdType", map));
|
||||||
log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType);
|
log.info("[setIdType][修改 MyBatis Plus 的 idType 为({})]", idType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue