2025-12-04 优化改造

This commit is contained in:
2025-12-04 17:00:07 +08:00
parent be56324763
commit 4282a126ef
22 changed files with 5660 additions and 98 deletions

View File

@@ -651,4 +651,5 @@ public class FileUtil {
directory.delete();
}
}
}

View File

@@ -3,7 +3,11 @@ package com.jeelowcode.tool.framework.common.util.string;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -15,6 +19,7 @@ import java.util.stream.Collectors;
*
* @author 芋道源码
*/
@Slf4j
public class StrUtils {
public static String maxLength(CharSequence str, int maxLength) {
@@ -76,4 +81,29 @@ public class StrUtils {
.collect(Collectors.toSet()); // 收集为 Set 集合
return deptId;
}
public static String encodeUrl(String rawUrl) {
try {
URL url = new URL(rawUrl);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(),
url.getPath(), url.getQuery(), url.getRef());
return uri.toASCIIString();
} catch (Exception e) {
log.warn("URL 编码失败,使用原始地址: {}", rawUrl, e);
return rawUrl;
}
}
public static String getCaseInsensitiveKey(JSONObject jsonObject, String key) {
if (jsonObject.containsKey(key)) {
return key;
}
for (String existingKey : jsonObject.keySet()) {
if (existingKey != null && existingKey.equalsIgnoreCase(key)) {
return existingKey;
}
}
// 默认返回原 key保证 put 时能插入
return key;
}
}