首页 > 编程语言 > 详细

小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_31、SpringBoot2整合模板引擎thymeleaf实战

时间:2019-08-28 09:22:44      阅读:93      评论:0      收藏:0      [点我收藏+]

笔记

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




 

小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_31、SpringBoot2整合模板引擎thymeleaf实战

原文:https://www.cnblogs.com/wangjunwei/p/11421765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!