Java 为什么不推荐使用 org.apache.common.lang3 StringEscapeUtils?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47817480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why was org.apache.common.lang3 StringEscapeUtils deprecated?
提问by gene b.
I couldn't find any explanation why StringEscapeUtils was deprecated from Apache Lang3 v3.7.
我找不到任何解释为什么 StringEscapeUtils 从 Apache Lang3 v3.7 中被弃用。
What are we supposed to use now for HTML escaping/unescaping
我们现在应该使用什么来进行 HTML 转义/非转义
采纳答案by Bj?rn Kechel
The class was moved from package
该课程已从包中移出
org.apache.commons.
lang3
org.apache.commons。
朗3
to
到
org.apache.commons.text
org.apache.commons。文本
You can replace the deprecated library easily:
您可以轻松替换已弃用的库:
In your build.gradle:
在你的 build.gradle 中:
implementation 'org.apache.commons:commons-text:1.8'
And in your class using StringEscapeUtils
make sure you import the correct class:
并在您的课程中使用StringEscapeUtils
确保您导入正确的课程:
import org.apache.commons.text.StringEscapeUtils;
1.8 is currently the newest version (last checked October 22nd 2019) but you can check the versions at maven: https://mvnrepository.com/artifact/org.apache.commons/commons-text
1.8 目前是最新版本(上次检查时间为 2019 年 10 月 22 日),但您可以在 maven 查看版本:https: //mvnrepository.com/artifact/org.apache.commons/commons-text
回答by Jamie Bisotti
Per the deprecation listing, it was moved to a new project -- commons-text
根据弃用清单,它已移至新项目——commons-text
回答by fn.
From Commons-lang 3.6 release notes:
The Apache Commons Community has recently set up the Commons Text component as a home for algorithms working on strings. For this reason most of the string focused functionality in Commons Lang has been deprecated and moved to Commons Text. This includes:
o All classes in the org.apache.commons.lang3.text and the org.apache.commons.lang3.text.translate packages o org.apache.commons.lang3.StringEscapeUtils o org.apache.commons.lang3.RandomStringUtils o The methods org.apache.commons.lang3.StringUtils.getJaroWinklerDistance and org.apache.commons.lang3.StringUtils.getLevenshteinDistance
For more information see the Commons Text website:
http://commons.apache.org/text
Apache Commons Community 最近建立了 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
回答by sapan prajapati
Do below steps
执行以下步骤
Add below dependency to your pom.xml (if using maven)
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.4</version>
<dependency>Import correct package as below
import org.apache.commons.text.StringEscapeUtils;- There is no such method unescapeHtml() in this class anymore, instead its two variations are available unescapeHtml3() and unescapeHtml4()
- Use unescapeHtml3() to unescape Html 3.0 characters
- Use unescapeHtml4() to unescape Html 4.0 characters
添加以下依赖到你的 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 字符进行转义