短视频素材网站免费大推荐,大兴网站建设设计公司,电脑为什么打不开网页,企业管理咨询有限公司经营范围需求背景#xff1a;由于公司安装的apollo比较老#xff0c;虽然新版本已经支持yaml格式了#xff0c;但升级apollo代价比较大#xff0c;有个项目配置文件之前放在项目里基于yaml编写的#xff0c;最近想切换到apollo存储配置文件。
先百度了下#xff0c;找了一个在线…需求背景由于公司安装的apollo比较老虽然新版本已经支持yaml格式了但升级apollo代价比较大有个项目配置文件之前放在项目里基于yaml编写的最近想切换到apollo存储配置文件。
先百度了下找了一个在线网站 https://www.toyaml.com/ 想了想 配置文件涉及到一些隐私使用在线网站转码不是太安全。萌生写一个yaml转 properties的工具类想法。 这里以JAVA为例
【人工智能】为啥我最近很少写python编程文章了浅谈AI编程RPA提升工作效率 在这篇文章中 我已经在IntelliJ IDEA2023.3.4 中安装好通义灵码下面就以idea中的通义灵码为例。
最初我不假思索直接提问: 请用java语言生成yaml转换properties工具类 最后的结果可想而知没达到自己想要的效果。
问题1、properties生成格式不正确。期望yaml包含多层树形结构要求生成的properties也要使用多层。
问题2、properties生成的顺序杂乱无章期望按照yaml的顺序
问题3yaml里包含注释AI没考虑到注释情况
通过一步一步调教最后得到可运行的代码。示例如下
import org.yaml.snakeyaml.Yaml; import java.io.; import java.nio.charset.StandardCharsets; import java.util.; import org.yaml.snakeyaml.Yaml;
public class YamlToProps {
public static void main(String[] args) throws IOException {String inputPath xxxx.yml;String outputPath xxxx.properties;convertYamlToProperties(inputPath, outputPath);}public static void convertYamlToProperties(String inputPath, String outputPath) throws IOException {// 读取 YAML 文件Yaml yaml new Yaml();FileInputStream fis new FileInputStream(inputPath);Reader reader new InputStreamReader(fis, StandardCharsets.UTF_8);MapString, Object yamlContent yaml.load(reader);// 使用扩展的 Properties 类存储结构化数据OrderedProperties props new OrderedProperties();// 遍历 YAML 内容并转换到 Properties 中convertToProperties(yamlContent, , props);// 保存到 properties 文件try (OutputStream output new FileOutputStream(outputPath)) {props.store(output, null);}
}private static void convertToProperties(MapString, Object content, String prefix, OrderedProperties props) {for (Map.EntryString, Object entry : content.entrySet()) {String key prefix.isEmpty() ? entry.getKey() : prefix . entry.getKey();Object value entry.getValue();if (value instanceof Map) {// 处理内嵌 Map 结构convertToProperties((MapString, Object) value, key, props);} else if (value instanceof List) {// 如果值是列表这里可以根据需求转换为逗号分隔的字符串或其他适合Properties的形式// 示例props.put(key, String.join(,, (ListString) value));} else {// 添加常规键值对props.put(key, value.toString());}}
}// 自定义扩展 Properties 类以保持顺序
static class OrderedProperties extends LinkedHashMapString, String {public synchronized EnumerationObject keys() {return Collections.enumeration(new ArrayList(keySet()));}public void store(OutputStream out, String comments) throws IOException {BufferedWriter bw new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));if (comments ! null !comments.isEmpty()) {bw.write(# comments.replace(\n, \n# ));bw.newLine();}for (Map.EntryString, String entry : this.entrySet()) {bw.write(entry.getKey() entry.getValue());bw.newLine();}bw.flush();}
}}
代码生成好后代码执行得到自己想要的工具类。
其实我们会发现 AI需要我们提供准确的话术才能一步步达到自己想要的结果我们要对它提要求 和验收标准。 这就和产品经理给程序员提需求一样 我们好比一个产品经理AI工具相当于开发工程师 如果产品经理提需求不具体由于每个人的思维理解不一致包括产品经理、开发工程师、测试工程师可能做出来的东西和需求方不一样。需求细节沟通在项目整个过程中真的很重要。
我最后想说AI工具只是辅助 我们的大脑思维才是 解决问题的关键。
原文链接https://mp.weixin.qq.com/s?__bizMzI5NDAzNzExNwmid2247484322idx1snbc8d3f2cfdee902875cfb4a82e31598bchksmec69b0b0db1e39a62c271cf9e41bf4aa71d0468cad339880461763f5833deaa5afb83fa6bd76token2090601571langzh_CN#rd