diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java index b29585db..e41ea782 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/YamlUtils.java @@ -2,11 +2,14 @@ package com.ruoyi.platform.utils; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.nodes.Node; +import org.yaml.snakeyaml.representer.Represent; +import org.yaml.snakeyaml.representer.Representer; import java.io.*; import java.util.Iterator; import java.util.Map; - +import org.yaml.snakeyaml.nodes.Tag; public class YamlUtils { /** @@ -20,8 +23,27 @@ public class YamlUtils { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); -// options.setPrettyFlow(true); - Yaml yaml = new Yaml(options); + options.setPrettyFlow(false); + + Representer representer = new Representer() { + { + // 重写字符串表示方法 + representers.put(String.class, new Represent() { + public Node representData(Object data) { + return representScalar(Tag.STR, (String) data, null); + } + }); + } + }; + + // 去掉引号时使用PLAIN样式 + representer.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN); + + // 创建Yaml实例 + Yaml yaml = new Yaml(representer, options); + +// Yaml yaml = new Yaml(options); + File directory = new File(path); if (!directory.exists()) { boolean isCreated = directory.mkdirs();