[java] view plain copy
- <code class="language-java">@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";
- }</code>
遍历Map 和 List
[html] view plain copy
- <code class="language-java"><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></code>
遍历List<Map>
[html] view plain copy
- <code class="language-java"><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></code>