@RequestMapping("/4")
public Object a3(Model model){
Map<String,User> map1=new HashedMap();
User user1;
for(int i=0;i<10;i++) {
user1=new User();
user1.setUsername("xiao.li"+i);
user1.setAge(i);
user1.setAddress("XXX的地址是"+i*2);
map1.put("J"+i, user1);
}
model.addAttribute("userMap",map1);
List<Map<String,User>> list = new ArrayList<Map<String,User>>();
User user;
for(int i=0;i<10;i++) {
Map<String,User> map=new HashedMap();
user=new User();
user.setUsername("xiao.li"+i);
user.setAge(i);
user.setAddress("XXX的地址是"+i*2);
map.put("A"+i, user);
list.add(map);
}
model.addAttribute("userList",list);
return "bb";
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<table border="1" >
<tr><td>No.</td>
<td>userStat</td>
<td>userEntry</td>
<td>UserObject</td>
<td>username</td>
<td>age</td>
<td>address</td>
</tr>
<tr th:each="userEntry,userStat:${userMap}">
<td th:text="${userStat.index}"></td>
<td th:text="${userStat}"></td>
<td th:text="${userEntry}"></td>
<td th:text="${userEntry.value}"></td>
<td th:text="${userEntry.value.username}"></td>
<td th:text="${userEntry.value.age}"></td>
<td th:text="${userEntry.value.address}"></td>
</tr>
</table>
<br/>
<table border="1" >
<tr><td>No.</td>
<td>userStat</td>
<td>userEntry</td>
<td>UserObject</td>
<td>username</td>
<td>age</td>
<td>address</td>
</tr>
<tr th:each="userEntry,userStat:${userList}">
<td th:text="${userStat.index}"></td>
<td th:text="${userStat}"></td>
<td th:text="${userEntry}"></td>
<td th:text="${userStat.current['A'+userStat.index]}"></td>
<td th:text="${userStat.current['A'+userStat.index].username}"></td>
<td th:text="${userStat.current['A'+userStat.index].age}"></td>
<td th:text="${userStat.current['A'+userStat.index].address}"></td>
</tr>
</table>
</body>
</html>