在thymeleaf中一般用th:text来绑定文本数据,但是当出现HTML标签时,如何将代码正确转译呢?
如:
username="<div style='color:red'>Tanya</div>"
使用th:text时
<span th:text="${username}"/>,您好</td>
视图结果:
<div style='color:red'>Tanya</div>,您好
想要的结果:
Tanya,您好
于是需要将th:text改为th:utext
<span th:utext="${username}"/>,您好</td>
视图结果:
Tanya,您好