【问题标题】:Using thymeleaf value in bootstrap alert在引导警报中使用百里香值
【发布时间】:2019-09-01 20:55:39
【问题描述】:

我想在验证后在我的 html 文件中使用后端生成的数据。我可以在jsp 中做到这一点,但thymeleaf 有问题。下面的代码 sn-p 显示了它在 jsp 中是如何工作的。第 3 行显示如何将 flashKind attr 附加到引导警报类中。 flashKind 的值可以是dangersuccess。我知道th:appendClass,但它不会在这里工作,因为它会将值附加为一个单独的单词。我需要它:alert-successalert-danger 一个字。

<div class="container">
    <c:if test="${not empty flashMessage}">
        <div class="alert alert-${flashKind} alert-dismissable">
          <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
          ${flashMessage}
        </div>
    </c:if>
</div>

【问题讨论】:

    标签: twitter-bootstrap spring-boot jsp thymeleaf


    【解决方案1】:

    您可以使用文字替换:

    <div th:class="|alert alert-${flashKind} alert-dismissable|">
    

    或者您可以将字符串附加在一起:

    <div th:class="alert alert-dismissable" th:classAppend="${'alert-' + flashKind}">
    or
    <div th:class="${'alert alert-' + flashKind + ' alert-dismissable'}">
    

    有很多方法可以做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 2018-09-07
      • 2013-09-10
      相关资源
      最近更新 更多