【问题标题】:Thymeleaf Could not parse as expression when trying to change background color尝试更改背景颜色时,Thymeleaf 无法解析为表达式
【发布时间】:2021-01-02 04:04:07
【问题描述】:

我正在尝试根据来自数据库的对象的变量 systemStatus 更改 div 的背景。

th:style="${system.systemStatus} == 1} ? 'background: green' : 'background: red'"

但我得到了错误:

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "${system.systemStatus} == 1} ? 'background: green' : 'background: red'" (template: "system-management" - line 48, col 41)

我尝试创建一个函数来获取systemStatus 作为字符串:

th:style="${system.systemStatusString()} == '1'} ? 'background: green' : 'background: red'"

但我得到了同样的错误。

整个div:

<div class="form-group" th:style="${system.systemStatus} == 1} ? 'background: green' : 'background: red'">
    <label for="id">ID: </label>
    <input type="text" th:value="${system.id}" th:name="id" th:id="id"  class="form-control" id="id" readonly />
    <br>
    <label for="machineId">Machine ID: </label>
    <input type="text" th:value="${system.machineId}" th:name="machineId" th:id="machineId"  class="form-control" id="machineId"/>
</div>

【问题讨论】:

  • 您的示例中有一个开头的{,但有两个结尾的}s。

标签: css spring spring-boot spring-mvc thymeleaf


【解决方案1】:

你有一个额外的}。实际代码应该是这样的

th:style="${system.systemStatus} == 1 ? 'background: green' : 'background: red'"

【讨论】:

    猜你喜欢
    • 2016-01-21
    • 2019-02-08
    • 1970-01-01
    • 2013-03-14
    • 2016-10-04
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    相关资源
    最近更新 更多