zoukankan      html  css  js  c++  java
  • SpringBootThymeleaf案例

    一.添加依赖

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

    六.启动类

  • 相关阅读:
    三、ADO.Net基础【04】简单查询
    Canvas 图片绕边旋转的小动画
    Canvas 剪切图片
    Canvas 图片平铺设置
    Canvas 给图形绘制阴影
    Canvas 图形组合方式
    [转]JS获取URL传参方法
    HTML5 FileReader接口学习笔记
    css3实现圆角边框渐变
    HTML5新增属性学习笔记
  • 原文地址:https://www.cnblogs.com/mayuan01/p/12030131.html
Copyright © 2011-2022 走看看