【问题标题】:How to concatenate th:text and static content with html tags in Thymeleaf?如何在 Thymeleaf 中将 th:text 和静态内容与 html 标签连接起来?
【发布时间】:2019-12-18 18:29:20
【问题描述】:
<div th:switch="${data.totalPercentage}">
    <td th:case="100" th:text="${data.totalPercentage}"/>
    <td th:case="*" th:text="${data.totalPercentage + '*'}" class="alert alert-warning font-weight-bold"/>
</div>

以上表达式有效,但我无法将 html 标记与 th:text 连接。我想将 * 替换为 fontawesome 标志图标 &lt;i class="fas fa-flag"&gt;&lt;/i&gt;。有什么建议吗?

【问题讨论】:

标签: spring-boot thymeleaf spring-boot-test


【解决方案1】:

没有真正的理由在这里连接,您应该考虑 HTML。

<div th:switch="${data.totalPercentage}">
  <td th:case="100" th:text="${data.totalPercentage}"/>
  <td th:case="*" class="alert alert-warning font-weight-bold">
    <span th:text="${data.totalPercentage}" /> <i class="fas fa-flag"></i>
  </td>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 2018-02-17
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多