@RequestMapping("/hello")
public String hello(Model map){
// 将要遍历的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
List userinfo =new ArrayList();
userinfo.add("周美玲");
userinfo.add("32");
userinfo.add("女");
userinfo.add("1985");
userinfo.add("19850014665");
map.addAttribute("userinfo", userinfo);
// 将要遍历的list
遍历Map,将会把上方的userhead渲染到table的头部;
遍历List,将会把userinfo渲染到table的body里。
遍历List
遍历map里嵌套list
参考:
https://github.com/thymeleaf/thymeleaf/issues/748
@RequestMapping
public ModelAndView show(HttpServletRequest req, HttpServletResponse resp, Model model){
Map file = new HashMap<>();
List AA = Arrays
.asList(new FileInfo("A1CLASS","A1ID","A1PATH","A1NAME"),
new FileInfo("A2CLASS","A2ID","A2PATH","A2NAME"),
new FileInfo("A3CLASS","A3ID","A3PATH","A3NAME"));
List BB = Arrays
.asList(new FileInfo("B1CLASS","B1ID","B1PATH","B1NAME"),
new FileInfo("B2CLASS","B2ID","B2PATH","B2NAME"),
new FileInfo("B3CLASS","B3ID","B3PATH","B3NAME"));
file.put("AA",AA);
file.put("BB",BB);
ModelAndView modelAndView = new ModelAndView("ia11/ia1101/ia1101");
model.addAttribute("file",file);
model.addAttribute("test","test");
return modelAndView;
}
...