Thymeleaf 遍历Map 输出Key Value

  • 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.结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/mar5342/article/details/85244669