Browse Source

fix the updating error for properties of type List

sunyj 8 years ago
parent
commit
3cc5550737
1 changed files with 14 additions and 1 deletions
  1. 14 1
      report/src/main/java/com/uas/report/DynamicProperties.java

+ 14 - 1
report/src/main/java/com/uas/report/DynamicProperties.java

@@ -218,7 +218,20 @@ public class DynamicProperties {
                 if (ObjectUtils.isEmpty(value)) {
                 if (ObjectUtils.isEmpty(value)) {
                     throw new IllegalArgumentException("配置项的值为空:" + expression + "=" + value);
                     throw new IllegalArgumentException("配置项的值为空:" + expression + "=" + value);
                 }
                 }
-                properties.setProperty(expression, value.toString());
+                // List 直接 toString,结果中会带 '[]'
+                if (value instanceof List) {
+                    List list = (List) value;
+                    StringBuilder builder = new StringBuilder();
+                    for (int i = 0; i < list.size(); i++) {
+                        if (i != 0) {
+                            builder.append(", ");
+                        }
+                        builder.append(list.get(i));
+                    }
+                    properties.setProperty(expression, builder.toString());
+                } else {
+                    properties.setProperty(expression, value.toString());
+                }
             }
             }
             properties.store(new FileOutputStream(new File(PROPERTY_FILE_NAME)), "report properties");
             properties.store(new FileOutputStream(new File(PROPERTY_FILE_NAME)), "report properties");
         } catch (IOException e) {
         } catch (IOException e) {