Thymeleaf:th:text内部的HTML标签

5

在th:text中可以使用HTML标记吗?

例如:

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

7

如果您使用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>

(这取决于您的实际需求,可能有可能没有。)

0
这个语法 [(${brand})] 可以实现。
<h3 th:object="${brand}" class="text-center text-black mt-5">
All Products By Brand 
<span>
    <b class="text-danger">[(${brand})]</b>
</span>

在这种情况下,对象是一个字符串,但你可以使用${object.something}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接