Browse Source

修复获取的配置为null时,返回值为"null"

周浩 9 years ago
parent
commit
fb52ba994c

+ 8 - 4
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/config/ConfigServiceImpl.java

@@ -11,6 +11,8 @@ import org.springframework.util.Assert;
 import org.webbuilder.utils.common.StringUtils;
 import org.webbuilder.utils.common.StringUtils;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Properties;
 
 
 /**
 /**
@@ -61,9 +63,9 @@ public class ConfigServiceImpl extends AbstractServiceImpl<Config, String> imple
      */
      */
     @Override
     @Override
     @Cacheable(value = CACHE_KEY, key = "'info.'+#name")
     @Cacheable(value = CACHE_KEY, key = "'info.'+#name")
-    public Properties get(String name) throws Exception {
+    public Map<Object, Object> get(String name) throws Exception {
         Config config = getMapper().selectByPk(name);
         Config config = getMapper().selectByPk(name);
-        if (config == null) return new Properties();
+        if (config == null) return new HashMap<>();
         return config.toMap();
         return config.toMap();
     }
     }
 
 
@@ -78,7 +80,9 @@ public class ConfigServiceImpl extends AbstractServiceImpl<Config, String> imple
     @Override
     @Override
     @Cacheable(value = CACHE_KEY, key = "'info.'+#name+'.key.'+#key")
     @Cacheable(value = CACHE_KEY, key = "'info.'+#name+'.key.'+#key")
     public String get(String name, String key) throws Exception {
     public String get(String name, String key) throws Exception {
-        return get(name).getProperty(key);
+        Object val = get(name).get(key);
+        if (val == null) return null;
+        return String.valueOf(val);
     }
     }
 
 
     /**
     /**
@@ -94,7 +98,7 @@ public class ConfigServiceImpl extends AbstractServiceImpl<Config, String> imple
     public String get(String name, String key, String defaultValue) {
     public String get(String name, String key, String defaultValue) {
         String val;
         String val;
         try {
         try {
-            val = this.get(name).getProperty(key);
+            val = this.get(name, key);
             if (val == null) {
             if (val == null) {
                 logger.error("获取配置:{}.{}失败,defaultValue:{}", name, key, defaultValue);
                 logger.error("获取配置:{}.{}失败,defaultValue:{}", name, key, defaultValue);
                 return defaultValue;
                 return defaultValue;