Thymeleaf:添加到现有值而不是替换它们

Posted

技术标签:

【中文标题】Thymeleaf:添加到现有值而不是替换它们【英文标题】:Thymeleaf: Add to existing values instead of replacing them 【发布时间】:2016-06-02 11:44:57 【问题描述】:

有没有办法告诉Thymeleaf 向标签添加参数而不是覆盖它们?

例子:

 <div class="a" th:class=$x ? 'b' : 'c'>

应该会导致

<div class="a b">

<div class="a c">

问候

【问题讨论】:

th:classappend 解决了问题。 【参考方案1】:

另一种方法是

th:attr="class=|a $x ? 'b' : 'c'|"

【讨论】:

以上是关于Thymeleaf:添加到现有值而不是替换它们的主要内容,如果未能解决你的问题,请参考以下文章