Thymeleaf 3语法来迭代List <list <t >>

时间:2019-05-08 06:14:21

标签: java arraylist thymeleaf

请考虑List中的以下List

List<List<SubSection>> listOfSubSectionLists

在Thymeleaf 3.0.9 TEXT模板中,我需要两个相应的循环嵌套,如下所示:

模板:

[# th:each="ssList, iterStat : ${listOfSubSectionLists}"]
    Title: Sub-Section [( ${ssList.iterStat.index+1} )]
    [# th:each="subSection : ${ssList.**?**}"] 
        Name: [( ${subSection.name} )]
        Address: [( ${subSection.address} )]
        Phone: [( ${subSection.phone} )]
    [/]
[/]

是否可以在上面的模板的第三行中获取内部列表?

1 个答案:

答案 0 :(得分:0)

如果您的变量如前所述,则列表仅为ssList。因此代码应为:

[# th:each="ssList, iterStat: ${listOfSubSectionLists}"]
    Title: Sub-Section [( ${iterStat.count} )]
    [# th:each="subSection: ${ssList}"] 
        Name: [( ${subSection.name} )]
        Address: [( ${subSection.address} )]
        Phone: [( ${subSection.phone} )]
    [/]
[/]

一些注意事项:

  • iterStat是它自己的变量(与ssList无关)。您无法使用表达式ssList.iterStat来访问它。
  • iterStat.count等同于iterStat.index + 1