一、目录展示
二、导入依赖

<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-thymeleafartifactId> dependency> dependencies>
在properties节点中增加,因为thymeleaf 模版需要html页面的所有元素都自身闭合!3.0之后的版本不在需要!
三、application.properties配置文件
四、Student实体类
五、ThymeleafController

package com.zn.controller; import com.zn.entity.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList; import java.util.List; @Controller @RequestMapping("/thymeleaf") public class ThymeleafController { @RequestMapping("/FirstThymeleaf") public String FirstThymeleaf(Model model){ System.out.println("成功进入ThymeleafController中的第一个方法呀"); Listlist=new ArrayList<>(); Student stu1=new Student(1,"张三"); Student stu2=new Student(2,"李四"); list.add(stu1); list.add(stu2); model.addAttribute("list",list); return "thymeleaf"; } }
六、thymeleaf.html页面
七、测试类
八、效果展示