mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Merge pull request #351 from ruansheng8/feat-aptConfig
feat: APT 支持从 Resources 目录进行配置
This commit is contained in:
commit
dfa3d708f9
@ -50,6 +50,8 @@ public class MybatisFlexConfig {
|
||||
protected final Properties properties = new Properties();
|
||||
|
||||
public MybatisFlexConfig(Filer filer) {
|
||||
// 先从 resources 目录读取 mybatis-flex.config 配置文件
|
||||
loadConfigFromResource();
|
||||
try {
|
||||
//target/classes/
|
||||
FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "mybatis-flex");
|
||||
@ -97,6 +99,21 @@ public class MybatisFlexConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigFromResource() {
|
||||
Properties resourceProp = new Properties();
|
||||
try (InputStream resourceStream = MybatisFlexConfig.class.getClassLoader().getResourceAsStream(APT_FILE_NAME)) {
|
||||
if (resourceStream == null) {
|
||||
return;
|
||||
}
|
||||
resourceProp.load(resourceStream);
|
||||
if (resourceProp != null && !resourceProp.isEmpty()) {
|
||||
properties.putAll(resourceProp);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String get(ConfigurationKey key) {
|
||||
return properties.getProperty(key.getConfigKey(), key.getDefaultValue());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user