【发布时间】:2016-04-12 05:43:43
【问题描述】:
当我尝试像这样在数组中使用索引变量时,带有 Thymeleaf 视图的 Spring Boot 应用程序给了我解析错误:
<tr th:each="cdItem, stat : *{commonDataItems}">
<td th:text=${stat.index}>Index</td>
<td> <input type="text" th:field=*{commonDataItems[__${stat.index}__].value>Value</td>
</tr>
这<td th:text=${stat.index}>Index</td> 行用于测试目的,它给出了正确的索引值,但下一行<td> <input type="text" th:field=*{commonDataItems[__${stat.index}__].value>Value</td> 给出了解析错误。
错误信息是:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "*{commonDataItems[__${stat.index}__].value" (common)
at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:238) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:79) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
有什么想法吗?
【问题讨论】:
-
您是缺少引号还是只是一个错字:
th:field="*{commonDataItems[__${stat.index}__].value" -
谢谢,就是这样。不过现在我并不太为自己感到骄傲 :) 你可以把它写成答案,我会接受的。
-
Ta,你只是需要一些新鲜的眼睛:-)
标签: spring-boot thymeleaf