cuikaidong
2025-06-12 066063ed92fdd40da4dfe21770557f3adba3e1af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package org.jeecg.common.util;
 
import org.apache.commons.lang.StringUtils;
import org.springframework.web.util.HtmlUtils;
 
/**
 * HTML 工具类
 */
public class HTMLUtils {
 
    /**
     * 获取HTML内的文本,不包含标签
     *
     * @param html HTML 代码
     */
    public static String getInnerText(String html) {
        if (StringUtils.isNotBlank(html)) {
            //去掉 html 的标签
            String content = html.replaceAll("</?[^>]+>", "");
            // 将多个空格合并成一个空格
            content = content.replaceAll("(&nbsp;)+", "&nbsp;");
            // 反向转义字符
            content = HtmlUtils.htmlUnescape(content);
            return content.trim();
        }
        return "";
    }
 
}