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

    六.启动类

  • 相关阅读:
    java类研究(String)
    webservices
    LoadRunner(软件性能测试工具)
    java线程
    lucene solr
    java IO
    实现一个可变长数组
    [北大程序设计与算法]--虚函数与多态的实例
    A1155 Heap Paths [堆的dfs]
    A1154 Vertex Coloring
  • 原文地址:https://www.cnblogs.com/mayuan01/p/12030131.html
Copyright © 2011-2022 走看看