From f5fe75ea698b5e9c3d13ba41e3856df28e13247b Mon Sep 17 00:00:00 2001 From: thinkgem Date: Wed, 13 Apr 2022 20:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81springboot=E5=B8=A6=E5=87=8F?= =?UTF-8?q?=E5=8F=B7=E7=9A=84key=E5=86=99=E6=B3=95=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=BD=AC=E6=8D=A2=E4=B8=BA=E9=A9=BC=E5=B3=B0=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/io/PropertiesUtils.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java b/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java index 8e375162..ccbef30d 100644 --- a/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java +++ b/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java @@ -126,7 +126,7 @@ public class PropertiesUtils { YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); bean.setResources(resource); for (Map.Entry entry : bean.getObject().entrySet()){ - properties.put(ObjectUtils.toString(entry.getKey()), + properties.put(getStandardKey(ObjectUtils.toString(entry.getKey())), ObjectUtils.toString(entry.getValue())); } configSet.add(location); @@ -181,7 +181,7 @@ public class PropertiesUtils { return value; } } - String value = properties.getProperty(key); + String value = properties.getProperty(getStandardKey(key)); if (value != null){ Matcher m = p1.matcher(value); while(m.find()) { @@ -231,6 +231,27 @@ public class PropertiesUtils { return ObjectUtils.toLong(getProperty(key, defValue)); } + /** + * 获取标准key,去减号并将后一个字母转换为大写 + * @author Think Gem + */ + private String getStandardKey(String key) { + StringBuilder sb = new StringBuilder(); + boolean upperCase = false; + for (int i = 0; i < key.length(); i++) { + char c = key.charAt(i); + if (c == '-') { + upperCase = true; + } else if (upperCase) { + sb.append(Character.toUpperCase(c)); + upperCase = false; + } else { + sb.append(c); + } + } + return sb.toString(); + } + /** * 设置环境属性 * @param environment