- 1.Java后台传Map至前台
Map<String,Object> map = new HashMap<>();
map.put("name","张三");
map.put("age","28");
map.put("sex","男");
model.addAttribute("map",map);
2.thymeleaf 遍历Map输出 key、value
<table class="layui-table">
<tr th:each="item,userStat:${map}">
<td th:text="${userStat.index}+1"></td>
<td th:text="${userStat.current.key}"></td><!-- key-->
<td th:text="${userStat.current.value}"></td><!-- value-->
</tr>
</table>
3.结果