【问题标题】:Spring Boot + Thymeleaf parsing error in loopSpring Boot + Thymeleaf 循环解析错误
【发布时间】: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>

&lt;td th:text=${stat.index}&gt;Index&lt;/td&gt; 行用于测试目的,它给出了正确的索引值,但下一行&lt;td&gt; &lt;input type="text" th:field=*{commonDataItems[__${stat.index}__].value&gt;Value&lt;/td&gt; 给出了解析错误。 错误信息是:

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


【解决方案1】:

缺少引号! 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>

【讨论】:

    猜你喜欢
    • 2018-11-30
    • 1970-01-01
    • 2021-09-14
    • 2021-09-25
    • 2019-06-11
    • 2018-04-16
    • 2014-06-30
    • 2020-10-07
    • 1970-01-01
    相关资源
    最近更新 更多