首页 > 编程语言 > 详细

SpringBootThymeleaf案例

时间:2019-12-12 18:28:43      阅读:69      评论:0      收藏:0      [点我收藏+]

一.添加依赖

      <!-- 添加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

六.启动类

技术分享图片

 

 

 

 

 

 

 

 

 

SpringBootThymeleaf案例

原文:https://www.cnblogs.com/mayuan01/p/12030131.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!