sup*_*toz 4 html java spring thymeleaf
如何在Thymeleaf中显示包含HTML标记的字符串?
所以这段代码:
<div th:each="content : ${cmsContent}">
<div class="panel-body" sec:authorize="hasRole('ROLE_ADMIN')">
<div th:switch="${content.reference}">
<div th:case="'home.admin'">
<p th:text="${content.text}"></p>
</div>
</div>
</div>
//More code....
Run Code Online (Sandbox Code Playgroud)
在这段代码中,${content.text}它在浏览器上生成了这个:
<p>test</p>
Run Code Online (Sandbox Code Playgroud)
但我想在浏览器上显示:
测试
Bal*_*ngh 12
您可以使用th:utext(非转义文本)进行此类方案.
简单地改变
<p th:text="${content.text}"></p>
Run Code Online (Sandbox Code Playgroud)
至
<p th:utext="${content.text}"></p>
Run Code Online (Sandbox Code Playgroud)
我建议在这里查看文档以了解使用Thymeleaf的所有信息.
| 归档时间: |
|
| 查看次数: |
5844 次 |
| 最近记录: |