57

我找不到任何解释为什么 StringEscapeUtils 从 Apache Lang3 v3.7 中被弃用。

https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html

我们现在应该使用什么来进行 HTML 转义/取消转义

4

4 回答 4

102

该类已从包中移出

org.apache.commons。lang3

org.apache.commons。文本

您可以轻松替换已弃用的库:

在您的 build.gradle 中:

implementation 'org.apache.commons:commons-text:1.9'

并在您的班级使用StringEscapeUtils确保您导入正确的班级:

import org.apache.commons.text.StringEscapeUtils;

1.9 当前是最新版本(最后检查于 2021 年 2 月 24 日),但您可以在 maven 上查看版本: https ://mvnrepository.com/artifact/org.apache.commons/commons-text

于 2018-04-04T09:34:19.803 回答
15

根据弃用列表,它被移到了一个新项目——commons-text

于 2017-12-14T16:03:54.290 回答
13

来自Commons-lang 3.6 发行说明

Apache Commons 社区最近将 Commons Text 组件设置为处理字符串的算法的家。由于这个原因,Commons Lang 中的大多数以字符串为中心的功能已被弃用并移至 Commons Text。这包括:

o org.apache.commons.lang3.text 和 org.apache.commons.lang3.text.translate 包中的所有类 o org.apache.commons.lang3.StringEscapeUtils o org.apache.commons.lang3.RandomStringUtils o方法 org.apache.commons.lang3.StringUtils.getJaroWinklerDistance 和 org.apache.commons.lang3.StringUtils.getLevenshteinDistance

有关更多信息,请参阅 Commons Text 网站:

http://commons.apache.org/text
于 2017-12-14T16:11:03.227 回答
7

执行以下步骤

  • 将以下依赖项添加到您的 pom.xml(如果使用 maven)
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-text</artifactId>
       <version>1.4</version>
    <dependency>

  • 导入正确的包如下
    import org.apache.commons.text.StringEscapeUtils;

  • 此类中不再有这样的方法 unescapeHtml(),取而代之的是它的两个变体 unescapeHtml3() 和 unescapeHtml4()
  • 使用 unescapeHtml3() 取消转义 Html 3.0 字符
  • 使用 unescapeHtml4() 取消转义 Html 4.0 字符
于 2018-09-24T06:57:30.893 回答