如何在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....
在這行代碼片段${content.text}中,它在瀏覽器上直接生成:
<p>test</p>
但我想在瀏覽器上顯示:
測驗
uj5u.com熱心網友回復:
對于此類場景,您可以使用th:utext(非轉義文本).簡單地改變
<p th:text="${content.text}"></p>
至
<p th:utext="${content.text}"></p>
我建議也要了解documentation here以了解使用Thymeleaf的所有資訊.
uj5u.com熱心網友回復:
同問
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/284143.html
標籤:其他技術討論專區
上一篇:AI克隆
