如何使用 thymeleaf 在 td 中设置颜色?

joe*_*hon 1 spring spring-mvc thymeleaf spring-boot

我尝试了 if object.qtdItem == 0,然后将 TD 的颜色设置为红色:

<td th:style="${obj.qtdItem == 0 ? 'color: red;'}" th:text="${obj.text}"></td>
Run Code Online (Sandbox Code Playgroud)

但这发生了

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

gly*_*ing 5

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

<td th:style="${obj.qtdItem == 0 ? 'color: red;' : 'color: some_other_color;'}}" th:text="${obj.text}"></td>
Run Code Online (Sandbox Code Playgroud)