zoukankan      html  css  js  c++  java
  • 小D课堂

    笔记

    4、SpringBoot2.x整合模板引擎thymeleaf实战
        讲解:SpringBoot2.x整合模板引擎thymeleaf实战

        官网地址:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html
        1、thymeleaf相关maven依赖
                <dependency>
                       <groupId>org.springframework.boot</groupId>
                       <artifactId>spring-boot-starter-thymeleaf</artifactId>
                </dependency>

        2、thymeleaf基础配置

            #开发时关闭缓存,不然没法看到实时页面
            spring.thymeleaf.cache=false
            spring.thymeleaf.mode=HTML5
            #前缀
            spring.thymeleaf.prefix=classpath:/templates/
            #编码
            spring.thymeleaf.encoding=UTF-8
            #类型
            spring.thymeleaf.content-type=text/html
            #名称的后缀
            spring.thymeleaf.suffix=.html

        3、建立文件夹
            1)src/main/resources/templates/tl/
            2)建立一个index.html

        4、简单测试代码编写和访问
            注意:$表达式只能写在th标签内部
            快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html

    开始 


    配置文件



    配置的跟路径直接指名了是templates下的tl文件夹作为根路径




    controller


    启动应用





    把templates文件夹加入到springboot的默认加载路径里面去。在application.properties这里spring.resources.static-locations里面配置

    所以需要把templates也加入到配置中。这样templates文件就会作为springboot默认加载会扫描加载的静态资源文件




    取数据,跳转到静态页




    th:text:模板语法替换了测试内容

    直接访问静态页

    快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html




     

  • 相关阅读:
    【Eolinker使用】接口测试--如何解决接口重定向
    ExtJS按钮
    Redis-消费模式
    Redis笔记教程
    C++中this指针的用法
    C — 对C语言的认识
    你还在迷茫什么
    2019-2020-1 20199324《Linux内核原理与分析》第四周作业
    2019-2020-1 20199324《Linux内核原理与分析》第三周作业
    2019-2020-1 20199324《Linux内核原理与分析》第二周作业
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11421765.html
Copyright © 2011-2022 走看看