zoukankan      html  css  js  c++  java
  • SpringBoot整合thymeleaf模板

    一、目录展示

       

    二、导入依赖

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

      在properties节点中增加,因为thymeleaf 模版需要html页面的所有元素都自身闭合!3.0之后的版本不在需要! 

      <thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>

      <thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>

    三、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中的第一个方法呀");
            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

    六、thymeleaf.html页面

      

     七、测试类

      

    八、效果展示

      

  • 相关阅读:
    洛谷—— P3353 在你窗外闪耀的星星
    洛谷—— P1238 走迷宫
    洛谷—— P1262 间谍网络
    9.8——模拟赛
    洛谷—— P1189 SEARCH
    算法
    May 22nd 2017 Week 21st Monday
    May 21st 2017 Week 21st Sunday
    May 20th 2017 Week 20th Saturday
    May 19th 2017 Week 20th Friday
  • 原文地址:https://www.cnblogs.com/Zzzzn/p/12029553.html
Copyright © 2011-2022 走看看