一、引入依赖(可在新建项目时勾选thymeleaf)
org.springframework.boot spring-boot-starter-thymeleaf
二、设置模板信息
@Controllerpublic class SysUserController { @GetMapping("/") public ModelAndView index(HttpSession session){ Object username = session.getAttribute("username"); if(username==null){ username="张三"; session.setAttribute("username",username); } ModelMap model = new ModelMap("message","个人信息减价") .addAttribute("username",username) .addAttribute("title",username) .addAttribute("date",new Date()) .addAttribute("foot","哈哈"); return new ModelAndView("index",model); }}
三、读取模板信息
Thymeleaf 标题
用户名
日期
参考: