您的位置:首页 > 编程语言 > Java开发

Thymeleaf基础 遍历List、Map、List<map>、Map<List>

2016-12-28 10:28 441 查看
controller
@RequestMapping("/hello")public String hello(Model map){Map user= new HashMap();user.put("name", "姓名");user.put("age", "年龄");user.put("sex", "性别");user.put("birthday", "生日");user.put("phonenumber", "手机");map.addAttribute("userhead", user);List userinfo =new ArrayList();userinfo.add("周美玲");userinfo.add("32");userinfo.add("女");userinfo.add("1985");userinfo.add("19850014665");map.addAttribute("userinfo", userinfo);List outerList=new ArrayList<>();Map innerMap=new HashMap<>();for (int i = 0; i < 10; i++) {innerMap.put("1", i);innerMap.put("1", i++);i++;outerList.add(innerMap);}map.addAttribute("listmap", outerList);return "/hello";}
遍历Map 和 List
<table class="table"><thead><th th:each="userhead : ${userhead}" th:text="${userhead.key}"></th><th th:each="userhead : ${userhead}" th:text="${userhead.value}"></th></thead><tbody ><td th:each="userinfo:${userinfo}" th:text="${userinfo}"></td></tbody></table>
遍历List<Map>
<ul th:each="lm : ${listmap}"><li th:each="entry : ${lm}" th:text="${entry.key}" ></li><li th:each="entry : ${lm}" th:text="${entry.value}"></li></ul>
L

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java thymeleaf