如何在 Thymeleaf 中使用 html 标签连接 th:text 和静态内容?

How to concatenate th:text and static content with html tags in Thymeleaf?

<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 标志图标 <i class="fas fa-flag"></i> 替换 *。有什么建议吗?

没有真正的理由在这里串联,你应该考虑 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>