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页面

      

     七、测试类

      

    八、效果展示

      

  • 相关阅读:
    win32_弹弹球游戏
    蓝桥杯评测_前n项和
    算法_fibonacci_递归求值
    PTA 分类
    _tmain() 和 main()
    VS2010 C++ 插件 VissualAssistX 安装
    vs2010 > LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
    int、long、long long 的取值范围
    B树 B-树 B+树 B*树
    PTA 5-10 公路村村通 (30)
  • 原文地址:https://www.cnblogs.com/Zzzzn/p/12029553.html
Copyright © 2011-2022 走看看