【发布时间】: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