forked from Gitlink/microservices
feat(制品库功能开发): 产品库增加打包下载产品库功能
工具类移动至公共方法:对字符串中,中文部分的内容进行urlEncode
This commit is contained in:
parent
6c4b75b4bf
commit
1dd4613060
|
|
@ -1,7 +1,11 @@
|
|||
package com.microservices.common.core.utils.html;
|
||||
|
||||
import com.microservices.common.core.utils.ServletUtils;
|
||||
import com.microservices.common.core.utils.StringUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 转义和反转义工具类
|
||||
*
|
||||
|
|
@ -30,7 +34,7 @@ public class EscapeUtil
|
|||
|
||||
/**
|
||||
* 转义文本中的HTML字符为安全的字符
|
||||
*
|
||||
*
|
||||
* @param text 被转义的文本
|
||||
* @return 转义后的文本
|
||||
*/
|
||||
|
|
@ -41,7 +45,7 @@ public class EscapeUtil
|
|||
|
||||
/**
|
||||
* 还原被转义的HTML特殊字符
|
||||
*
|
||||
*
|
||||
* @param content 包含转义符的HTML内容
|
||||
* @return 转换后的字符串
|
||||
*/
|
||||
|
|
@ -52,7 +56,7 @@ public class EscapeUtil
|
|||
|
||||
/**
|
||||
* 清除所有HTML标签,但是不删除标签内的内容
|
||||
*
|
||||
*
|
||||
* @param content 文本
|
||||
* @return 清除标签后的文本
|
||||
*/
|
||||
|
|
@ -63,7 +67,7 @@ public class EscapeUtil
|
|||
|
||||
/**
|
||||
* Escape编码
|
||||
*
|
||||
*
|
||||
* @param text 被编码的文本
|
||||
* @return 编码后的字符
|
||||
*/
|
||||
|
|
@ -104,7 +108,7 @@ public class EscapeUtil
|
|||
|
||||
/**
|
||||
* Escape解码
|
||||
*
|
||||
*
|
||||
* @param content 被转义的内容
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
|
|
@ -170,4 +174,25 @@ public class EscapeUtil
|
|||
}
|
||||
return url.replaceAll("(?<!(http:|https:))/+", "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字符串中,中文部分的内容进行urlEncode
|
||||
*
|
||||
* @param str 字符串
|
||||
* @return urlEncode后的字符串
|
||||
*/
|
||||
public static String encodeChineseCharacters(String str) {
|
||||
// 正则表达式匹配中文字符
|
||||
Pattern pattern = Pattern.compile("[\\u4e00-\\u9fa5,。、;:?!“”‘’【】《》()\\[\\]{}<>]+");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
// 对匹配到的中文字符进行URL编码
|
||||
String encoded = ServletUtils.urlEncode(matcher.group());
|
||||
matcher.appendReplacement(sb, encoded);
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.microservices.pms.utils;
|
||||
|
||||
import com.microservices.common.core.exception.ServiceException;
|
||||
import com.microservices.common.core.utils.ServletUtils;
|
||||
import com.microservices.system.api.domain.SysFileBytes;
|
||||
import feign.Response;
|
||||
|
||||
|
|
@ -11,8 +10,6 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author otto
|
||||
|
|
@ -69,22 +66,6 @@ public class PmsUtils {
|
|||
}
|
||||
}
|
||||
|
||||
// 对字符串中,中文部分的内容进行urlEncode
|
||||
public static String encodeChineseCharacters(String str) {
|
||||
// 正则表达式匹配中文字符
|
||||
Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
// 对匹配到的中文字符进行URL编码
|
||||
String encoded = ServletUtils.urlEncode(matcher.group());
|
||||
matcher.appendReplacement(sb, encoded);
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径中文件所在的文件夹
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue