遍历list:
Controller:
@RequestMapping("/show3")
public String showInfo3(Model model){
List<Users> list = new ArrayList<>();
list.add(new Users(1,"张三",20));
list.add(new Users(2,"李四",22));
list.add(new Users(3,"王五",24));
model.addAttribute("list", list);
return "index3";
}
html:
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr th:each="u : ${list}">
<td th:text="${u.userid}"></td>
<td th:text="${u.username}"></td>
<td th:text="${u.userage}"></td>
</tr>
</table>
遍历Map:
html:
<table align="center" border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr th:each="maps:${map}">
<td th:each="entry:${maps}" th:text="${entry.value.userId}"></td>
<td th:each="entry:${maps}" th:text="${entry.value.userName}"></td>
<td th:each="entry:${maps}" th:text="${entry.value.userAge}"></td>
</tr>
</table>