代码之家  ›  专栏  ›  技术社区  ›  Nathan Fawcett

Thymeleaf中的嵌套循环

  •  1
  • Nathan Fawcett  · 技术社区  · 6 年前

    我是个新手。

    Classroom Student :每个教室包含一个 List<Student> 我可以有一个教室列表: List<Classroom>

                for(int i = 0; i < classroomList.size(); i++){
                    System.out.println(classroomList.get(i).getRoomName());
                    for(int x = 0; x < studentList.size(); x++){
                        System.out.println(studentList.get(x));
                    }
                }
    

    {classroom1{joe1,joe2}, classroom2{joe3}}...

    但是我需要能够用Thymeleaf在HTML中完成这项工作(通过传递一个教室列表),这样我才能使它看起来很漂亮。

    非常感谢您的帮助。谢谢!

    1 回复  |  直到 6 年前
        1
  •  3
  •   user987339 jbandi    6 年前

    th:each :

    <div th:each="classroom : ${classroomList}">
        <div>"${classroom.name}"</div>
        <ul>
          <div th:each="student : ${classroom.studentList}">
             <li>"${student.name}"</li>
          </div>
        </ul>
    </div>