我正在尝试在我的grails测试报告中打印我的 Spock 规格的步骤描述。
我print/println
用来在报告中提供这些信息。
问题是我想将一些数据打印为 HTML 表格,但是当我打印一些 html 标记(即<table>
)时,<
and >
(小于和大于符号)被打印为<
and >
。
有没有办法在不转换标签的情况下打印标签?
这里有一个答案:Java: How to unescape HTML character entity in Java? ,推荐使用org.apache.commons.lang.StringEscapeUtils.unescapeHtml(String str)。
转义HTML
公共静态字符串 unescapeHtml(String str)
Unescapes a string containing entity escapes to a string containing the actual
对应于转义的 Unicode 字符。支持 HTML 4.0 实体。
For example, the string "<Français>" will become "<Français>" If an entity is unrecognized, it is left alone, and inserted verbatim into
结果字符串。例如 ">&zzzz;x" 将变为 ">&zzzz;x"。