(和)后台解析

前台传输字符“)”或者“(”,后台接收到的都是(和)

所以需要做一步转换。

org.apache.commons.lang.StringEscapeUtils.unescapeHtml

补充下:

因为前台传过来的类似于“fhakfhakf& #40;u& #41;”这样一串字符,无法进行解码,且这串字符存在空格,无法使用String.replaceAll进行替换。

可以用正则替换所有符合的空格

public static String unescapeHtml(String htmlStr){
    Pattern pattern = Pattern.compile("&.*?;");
    Matcher matcher = pattern.matcher(htmlStr);
    StringBuffer str = new StringBuffer();
    String result = htmlStr;
    while(matcher.find()){
        result = result.replaceFirst(matcher.group(),matcher.group().replaceAll(" ",""));
    }
    return StringEscapeUtils.unescapeHtml(result);
}



原文地址:https://www.cnblogs.com/kongkongFabian/p/11240567.html