Thymeleaf:th:text中的HTML标签



是否可以在th:text中包含Html标签?

例如:

<h2 th:text="'LOCATION INFO Device &lt;strong&gt;' + ${deviceKey} + ' &lt;/strong&gt;  at ' + ${deviceEventTime} ">

是的,如果您使用 th:utext 而不是 th:text,您所拥有的东西就会起作用。

<h2 th:utext="'LOCATION INFO Device &lt;strong&gt;' + ${deviceKey} + ' &lt;/strong&gt;  at ' + ${deviceEventTime}" />

但是,我个人会这样格式化它:

<h2>
  LOCATION INFO Device 
  <strong th:text="${deviceKey}" />
  at
  <span th:text="${deviceEventTime}">
</h2>

(这也许是可能的,也可能是不可能的,这取决于你的实际要求。

最新更新