Spring HtmlUtils把HTML编码转义输出
org.springframework.web.util.HtmlUtils 可以实现HTML标签及转义字符之间的转换。
示例代码:
String s = HtmlUtils.htmlEscape("<div>hello world</div><p> </p>");
System.out.println(s);
String s2 = HtmlUtils.htmlUnescape(s);
System.out.println(s2);
转义后如图所示: