一.添加依赖

      <!-- 添加thymeleaf模版的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

二.entity实体类

 三.resources/templates/thymeleaf.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>SpringBoot整合thymeleaf模板</title>
</head>
<body>
<table border="1px">
    <tr>
        <td>学生编号</td>
        <td>学生姓名</td>
    </tr>

<tr th:each="list:${list}">
    <td th:text="${list.stu_id}"></td>
    <td th:text="${list.stu_name}"></td>
</tr>
</table>
</body>
</html>
View Code

四.application.properties

wu

五.controller

package com.my.controller;

import com.my.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 ThymeleafControllers {
    @RequestMapping("/FirstThymeleaf")
    public String FirstThymeleaf(Model model){
        System.out.println("成功进入ThymeleafController中的第一个方法呀");
        List<Student> list=new ArrayList<>();
        Student stu1=new Student(1,"张三");
        Student stu2=new Student(2,"李四");
        list.add(stu1);
        list.add(stu2);
        model.addAttribute("list",list);
        return "thymeleaf";

    }

}
View Code

六.启动类

12-17 06:40