java转义文本中的HTML字符为安全的字
,以下字符被转义:
' 替换为 ' (' doesn't work in HTML4)
" 替换为 "
& 替换为 &
< 替换为 <
> 替换为 >
1.先添加hutool依赖到pom
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.16</version></dependency>
2.代码案例
public static void main(String[] args) throws Exception{String escape = HtmlUtil.escape(">=和<=");System.out.println(escape);}