Spring Boot + Thymeleaf 循环解析错误
Spring Boot + Thymeleaf parsing error in loop
Spring 当我尝试像这样在数组中使用索引变量时,使用 Thymeleaf 视图启动应用程序时出现解析错误:
<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"
所以:
<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>
Spring 当我尝试像这样在数组中使用索引变量时,使用 Thymeleaf 视图启动应用程序时出现解析错误:
<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"
所以:
<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>