以html标签为载体在html的标签下实现对数据的
package com.kaikeba.thymeleaf.controller; import com.kaikeba.thymeleaf.VO.UserVo; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class ThymeleafController { @RequestMapping("/some") public String indexHandle(Model model) { model.addAttribute("hello", "hello thymeleaf"); model.addAttribute("user",new UserVo(1,"张三",23)); return "index"; } }
<!DOCTYPE html> <html lang="en" xmlns:th="https://www.thymeleaf.org/"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <p th:text="${hello}">现在显示的是静态数据</p> <div>现在显示的是静态数据</div> <span>现在显示的是静态数据</span> <hr> <p th:object="${user}"> <p>姓名:<span th:text="${user.name}"></span></p> <p>年龄:<span th:text="${user.age}"></span></p> </div> </body> </html>