繁体   English   中英

无法遍历列表 <List<String> &gt;使用Thymeleaf / Spring-Boot

[英]Unable to iterate over List<List<String>> using Thymeleaf / Spring-Boot

使用Thymeleaf,我无法遍历List <List <String >>

 <tr th:each="row : ${rows}">
      <td th:text="${row[0]}"></td>
      <td th:text="${row[1]}"></td>
 </tr>

每行具有多个值。

渲染时,出现以下异常

2016-11-02 20:40:21.033 ERROR 44829 --- [nio-5252-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-5252-exec-1] Exception processing template "completed": Exception evaluating SpringEL expression: "row[1]" (completed:217)
2016-11-02 20:40:21.034 ERROR 44829 --- [nio-5252-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/test-dashboard] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "row[1]" (completed:217)] with root cause

org.springframework.expression.spel.SpelEvaluationException: EL1025E:(pos 3): The collection has '1' elements, index '1' is invalid

提前致谢。

双循环怎么样?

请注意 ,我不确定此XHTML的有效性,您可能必须在TR下使用与SPAN不同的HTML元素)

<tr th:each="row : ${rows}">
      <span th:each="s : ${row}">
         <td th:text="${s}"></td>             
      </span>
 </tr>

如果您只想为它们每个生成一个TD ,请在TD上添加另一个for-each:

<tr th:each="row : ${rows}">
     <td th:each="rowValue : ${row}" th:text="${rowValue}"></td>
</tr>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM