Thymeleaf基础 遍历List、Map、对象属性

您所在的位置:网站首页 thymeleaf循环map Thymeleaf基础 遍历List、Map、对象属性

Thymeleaf基础 遍历List、Map、对象属性

2023-11-07 10:02| 来源: 网络整理| 查看: 265

项目截图 图片.png

controller

package com.neo.web; import com.neo.entity.People; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import java.util.*; @RestController public class Controller { @GetMapping("/") public People get() { return new People ("1", "socks", "123456", new Date(), "GMT"); } private List peopleList =new ArrayList();{ peopleList.add( new People ("1", "socks1", "111111", new Date(), "GMT1")); peopleList.add( new People ("2", "socks2", "514730", new Date(), "GMT2")); peopleList.add( new People ("3", "socks3", "112233", new Date(), "GMT3")); peopleList.add( new People ("4", "socks4", "147892", new Date(), "GMT4")); } @GetMapping("z") public ModelAndView index(){ return new ModelAndView("user/user","userList",peopleList); } @GetMapping("z/{id}") public ModelAndView index(@PathVariable("id") int id){ ModelAndView mv =new ModelAndView("user/user2"); Map user= new HashMap(); user.put("name", "姓名"); user.put("age", "年龄"); user.put("sex", "性别"); user.put("birthday", "生日"); user.put("phonenumber", "手机"); System.out.println(peopleList.get(id)); People p =new People("1", "socks", "123456", new Date(), "GMT"); mv.addObject("p",p); mv.addObject("userList",peopleList); mv.addObject("map",user); mv.addObject("people",peopleList.get(id)); mv.addObject("userList",peopleList); return mv; } }

user2.html

userList .bodystyle{ filter:alpha(opacity=100); -moz-opacity:1; -khtml-opacity: 1; opacity: 1; width:100%; position:absolute; background-attachment:fixed; } id name createTime timeZone password Edit Delete neo neo Otto 6 6 edit delete

图片.png

https://blog.csdn.net/u012485114/article/details/53906250

Thymeleaf 模板引擎中文文档: https://blog.csdn.net/zhangcc233/article/details/80831056

https://www.jianshu.com/p/908b48b10702



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3