【发布时间】:2019-01-04 21:12:51
【问题描述】:
我有 2 个列表; allkontrols(2 个元素),risk.kontrols(1 个元素)
如果 risk.kontrols 列表包含它,我将所有 kontrols 列为复选框并尝试“选择”它们。
risk.kontrols 中的一个元素也在 allkontrols 中。
所以,当我试图打印这个结果时:
<div th:each="kontrol : ${allkontrols}" th:text="${#lists.contains(risk.kontrols, kontrol)}"/>
我得到了结果
true
false
到这里为止一切都很好。现在,当我尝试用数据填充它们时,我得到了错误。代码如下:
<div th:each="kontrol : ${allkontrols}" class="items form-control-lg">
<label>
<input th:value="${kontrol.id}" th:selected="{#lists.contains(risk.kontrols, kontrol)}" type="checkbox" class="flat">
<div style="display: inline-block;" th:utext=" ${kontrol.name}"></div>
</label>
</div>
错误部分: th:selected="{#lists.contains(risk.kontrols, kontrol)}"
堆栈跟踪:
2018-07-27 20:36:55 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "view/riskkontrol.html")] with root cause
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "{#lists.contains(risk.kontrols, kontrol)}" (template: "riskkontrol" - line 44, col 140)
【问题讨论】:
标签: spring spring-boot thymeleaf