【问题标题】:How to set color in td with thymeleaf?如何用百里香在 td 中设置颜色?
【发布时间】:2017-11-04 23:27:33
【问题描述】:

我试过object.qtdItem == 0,然后把TD的颜色设置为红色:

<td th:style="${obj.qtdItem == 0 ? 'color: red;'}" th:text="${obj.text}"></td>

但这发生了

error: Caused by:
org.springframework.expression.spel.SpelParseException: Expression
[perfil.qtdItem == 0 ? 'red'] @38: EL1044E: Unexpectedly ran out of
input

【问题讨论】:

    标签: spring spring-mvc spring-boot thymeleaf


    【解决方案1】:

    三元语句需要else 子句,例如

    <td th:style="${obj.qtdItem == 0 ? 'color: red;' : 'color: some_other_color;'}}" th:text="${obj.text}"></td>
    

    【讨论】:

    • 如果您使用较新的 Thymeleaf 会更好:th:style="${obj.qtdItem == 0 ? 'color: red;' : _ }}" 请参阅 _ 以获取 no action else 子句
    【解决方案2】:

    这对我有用。

    th:style="|${obj.qtdItem == 'red' ? 'color: red;' : 'color: green;'}|"
    

    【讨论】:

    • 欢迎来到 Stack Overflow!虽然这段代码可以解决问题,including an explanation 解决问题的方式和原因确实有助于提高帖子的质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人。请edit您的回答添加解释并说明适用的限制和假设。
    【解决方案3】:

    另一种选择:

    th:style="|${obj.qtdItem == 'red' ? 'color: red;' : 'color: green;'}|"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      相关资源
      最近更新 更多