国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

網(wǎng)頁制作素材按鈕圖標(biāo)seo編輯招聘

網(wǎng)頁制作素材按鈕圖標(biāo),seo編輯招聘,廣東省建設(shè)信息中心,wordpress設(shè)置banner目前搜索到的大部分代碼都存在以下問題: 復(fù)雜結(jié)構(gòu)解析丟失解析后順序錯亂 所以自己寫了一個,經(jīng)過不充分測試,基本滿足使用??梢灾苯釉诰€使用 在線地址 除了yml和properties互轉(zhuǎn)之外,還可以生成代碼、sql轉(zhuǎn)json等,可…

目前搜索到的大部分代碼都存在以下問題:

  • 復(fù)雜結(jié)構(gòu)解析丟失
  • 解析后順序錯亂

所以自己寫了一個,經(jīng)過不充分測試,基本滿足使用??梢灾苯釉诰€使用 在線地址
除了yml和properties互轉(zhuǎn)之外,還可以生成代碼、sql轉(zhuǎn)json等,可以去用一下,用愛發(fā)電,感謝支持!
在這里插入圖片描述
源碼:

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.yaml.snakeyaml.Yaml;import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;/*** @author Deng.Weiping* @since 2023/11/28 13:57*/
@Slf4j
public class PropertiesUtil {/*** yaml 轉(zhuǎn) Properties** @param input* @return*/public static String castToProperties(String input) {Map<String, Object> propertiesMap = new LinkedHashMap<>();Map<String, Object> yamlMap = new Yaml().load(input);flattenMap("", yamlMap, propertiesMap);StringBuffer strBuff = new StringBuffer();propertiesMap.forEach((key, value) -> strBuff.append(key).append("=").append(value).append(StrUtil.LF));return strBuff.toString();}/*** Properties 轉(zhuǎn) Yaml** @param input* @return*/public static String castToYaml(String input) {try {Map<String, Object> properties = readProperties(input);return properties2Yaml(properties);} catch (Exception e) {log.error("property 轉(zhuǎn) Yaml 轉(zhuǎn)換失敗", e);}return null;}private static Map<String, Object> readProperties(String input) throws IOException {Map<String, Object> propertiesMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 保證順序for (String line : input.split(StrUtil.LF)) {if (StrUtil.isNotBlank(line)) {// 使用正則表達(dá)式解析每一行中的鍵值對Pattern pattern = Pattern.compile("\\s*([^=\\s]*)\\s*=\\s*(.*)\\s*");Matcher matcher = pattern.matcher(line);if (matcher.matches()) {String key = matcher.group(1);String value = matcher.group(2);propertiesMap.put(key, value);}}}return propertiesMap;}/*** 遞歸 Map 集合,轉(zhuǎn)為 Properties集合** @param prefix* @param yamlMap* @param treeMap*/private static void flattenMap(String prefix, Map<String, Object> yamlMap, Map<String, Object> treeMap) {yamlMap.forEach((key, value) -> {String fullKey = prefix + key;if (value instanceof LinkedHashMap) {flattenMap(fullKey + ".", (LinkedHashMap) value, treeMap);} else if (value instanceof ArrayList) {List values = (ArrayList) value;for (int i = 0; i < values.size(); i++) {String itemKey = String.format("%s[%d]", fullKey, i);Object itemValue = values.get(i);if (itemValue instanceof String) {treeMap.put(itemKey, itemValue);} else {flattenMap(itemKey + ".", (LinkedHashMap) itemValue, treeMap);}}} else {treeMap.put(fullKey, value.toString());}});}/*** properties 格式轉(zhuǎn)化為 yaml 格式字符串** @param properties* @return*/private static String properties2Yaml(Map<String, Object> properties) {if (CollUtil.isEmpty(properties)) {return null;}Map<String, Object> map = parseToMap(properties);StringBuffer stringBuffer = map2Yaml(map);return stringBuffer.toString();}/*** 遞歸解析為 LinkedHashMap** @param propMap* @return*/private static Map<String, Object> parseToMap(Map<String, Object> propMap) {Map<String, Object> resultMap = new LinkedHashMap<>();try {if (CollectionUtils.isEmpty(propMap)) {return resultMap;}propMap.forEach((key, value) -> {if (key.contains(".")) {String currentKey = key.substring(0, key.indexOf("."));if (resultMap.get(currentKey) != null) {return;}Map<String, Object> childMap = getChildMap(propMap, currentKey);Map<String, Object> map = parseToMap(childMap);resultMap.put(currentKey, map);} else {resultMap.put(key, value);}});} catch (Exception e) {e.printStackTrace();}return resultMap;}/*** 獲取擁有相同父級節(jié)點(diǎn)的子節(jié)點(diǎn)** @param propMap* @param currentKey* @return*/private static Map<String, Object> getChildMap(Map<String, Object> propMap, String currentKey) {Map<String, Object> childMap = new LinkedHashMap<>();try {propMap.forEach((key, value) -> {if (key.contains(currentKey + ".")) {key = key.substring(key.indexOf(".") + 1);childMap.put(key, value);}});} catch (Exception e) {e.printStackTrace();}return childMap;}/*** map集合轉(zhuǎn)化為yaml格式字符串** @param map* @return*/public static StringBuffer map2Yaml(Map<String, Object> map) {//默認(rèn)deep 為零,表示不空格,deep 每加一層,縮進(jìn)兩個空格return map2Yaml(map, 0);}/*** 把Map集合轉(zhuǎn)化為yaml格式 String字符串** @param propMap map格式配置文件* @param deep    樹的層級,默認(rèn)deep 為零,表示不空格,deep 每加一層,縮進(jìn)兩個空格* @return*/private static StringBuffer map2Yaml(Map<String, Object> propMap, int deep) {StringBuffer yamlBuffer = new StringBuffer();try {if (CollectionUtils.isEmpty(propMap)) {return yamlBuffer;}String space = getSpace(deep);for (Map.Entry<String, Object> entry : propMap.entrySet()) {Object valObj = entry.getValue();if (entry.getKey().contains("[") && entry.getKey().contains("]")) {String key = entry.getKey().substring(0, entry.getKey().indexOf("[")) + ":";yamlBuffer.append(space + key + "\n");propMap.forEach((itemKey, itemValue) -> {if (itemKey.startsWith(key.substring(0, entry.getKey().indexOf("[")))) {yamlBuffer.append(getSpace(deep + 1) + "- ");if (itemValue instanceof Map) {StringBuffer valStr = map2Yaml((Map<String, Object>) itemValue, 0);String[] split = valStr.toString().split(StrUtil.LF);for (int i = 0; i < split.length; i++) {if (i > 0) {yamlBuffer.append(getSpace(deep + 2));}yamlBuffer.append(split[i]).append(StrUtil.LF);}} else {yamlBuffer.append(itemValue + "\n");}}});break;} else {String key = space + entry.getKey() + ":";if (valObj instanceof String) { //值為value 類型,不用再繼續(xù)遍歷yamlBuffer.append(key + " " + valObj + "\n");} else if (valObj instanceof List) { //yaml List 集合格式yamlBuffer.append(key + "\n");List<String> list = (List<String>) entry.getValue();String lSpace = getSpace(deep + 1);for (String str : list) {yamlBuffer.append(lSpace + "- " + str + "\n");}} else if (valObj instanceof Map) { //繼續(xù)遞歸遍歷Map<String, Object> valMap = (Map<String, Object>) valObj;yamlBuffer.append(key + "\n");StringBuffer valStr = map2Yaml(valMap, deep + 1);yamlBuffer.append(valStr.toString());} else {yamlBuffer.append(key + " " + valObj + "\n");}}}} catch (Exception e) {e.printStackTrace();}return yamlBuffer;}/*** 獲取縮進(jìn)空格** @param deep* @return*/private static String getSpace(int deep) {StringBuffer buffer = new StringBuffer();if (deep == 0) {return "";}for (int i = 0; i < deep; i++) {buffer.append("  ");}return buffer.toString();}}
http://aloenet.com.cn/news/32560.html

相關(guān)文章:

  • 做服裝要看國外哪些網(wǎng)站長尾關(guān)鍵詞挖掘
  • 兩學(xué)一做材料上哪個網(wǎng)站找最佳的搜索引擎
  • 可以自己做網(wǎng)站優(yōu)化嗎體驗(yàn)式營銷經(jīng)典案例
  • 門戶網(wǎng)站建設(shè)談判搜狗站長平臺主動提交
  • 網(wǎng)站開發(fā)的具體流程網(wǎng)站發(fā)布平臺
  • 西寧網(wǎng)站seo公司seo推廣效果
  • 國內(nèi)頂尖網(wǎng)站設(shè)計公司口碑營銷的定義
  • 免費(fèi)做外貿(mào)的網(wǎng)站深圳谷歌推廣公司
  • 幫彩票網(wǎng)站做流量提升seo賺錢方式
  • 東莞網(wǎng)站建設(shè) 環(huán)保設(shè)備自創(chuàng)網(wǎng)站
  • 武漢建站中心百度廣告競價排名
  • 淘客網(wǎng)站要怎么做黑帽seo技巧
  • 政府網(wǎng)站建設(shè)事例常見的推廣方式有哪些
  • 遼河油田建設(shè)有限公司網(wǎng)站找個網(wǎng)站
  • 9420高清免費(fèi)視頻在線觀看武漢抖音seo搜索
  • 做網(wǎng)站需要懂什么廣州網(wǎng)頁定制多少錢
  • 做怎么樣的網(wǎng)站好如何自己弄個免費(fèi)網(wǎng)站
  • 怎么做一元購網(wǎng)站代運(yùn)營公司哪家好一些
  • 做網(wǎng)站靠教育賺錢seo的基礎(chǔ)優(yōu)化
  • com是什么網(wǎng)站廣告推廣策劃
  • 我的世界做披風(fēng)網(wǎng)站友情鏈接檢測的特點(diǎn)
  • 松原網(wǎng)站制作如何讓百度收錄自己的網(wǎng)站
  • 婁底網(wǎng)站建設(shè)的話術(shù)北京seo運(yùn)營推廣
  • 網(wǎng)站建設(shè)基礎(chǔ)大綱文案軟文推廣有哪些
  • 網(wǎng)站開發(fā)用的那些語言怎么在百度發(fā)布自己的文章
  • 花店網(wǎng)站建設(shè)環(huán)境分析百度搜索什么關(guān)鍵詞能搜到網(wǎng)站
  • 午夜做網(wǎng)站營銷網(wǎng)站的宣傳、推廣與運(yùn)作
  • 淘寶站內(nèi)推廣方式有哪些班級優(yōu)化大師使用心得
  • 許昌做網(wǎng)站漢獅網(wǎng)絡(luò)青島seo關(guān)鍵詞優(yōu)化公司
  • 網(wǎng)上建站賺錢微信公眾號推廣軟文案例