首页 > 编程语言 > 详细

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

时间:2019-08-28 09:25:33      阅读:164      评论:0      收藏:0      [点我收藏+]

笔记

3、SpringBoot2.x整合模板引擎freemarker实战
    简介:SpringBoot2.x整合模板引擎freemarker实战

    1、Freemarker相关maven依赖
        <!-- 引入freemarker模板引擎的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

    2、Freemarker基础配置
        # 是否开启thymeleaf缓存,本地为false,生产建议为true
        spring.freemarker.cache=false

        spring.freemarker.charset=UTF-8
        spring.freemarker.allow-request-override=false
        spring.freemarker.check-template-location=true
        
        #类型
        spring.freemarker.content-type=text/html

        spring.freemarker.expose-request-attributes=true
        spring.freemarker.expose-session-attributes=true
        
        #文件后缀
        spring.freemarker.suffix=.ftl
        #路径
        spring.freemarker.template-loader-path=classpath:/templates/
        

    3、建立文件夹
        1)src/main/resources/templates/fm/user/
        2)建立一个index.ftl
        3)user文件夹下面建立一个user.html



    4、简单测试代码编写和访问

开始

添加引用
技术分享图片
配置文件
技术分享图片
这里因为我们是本地设置为false
技术分享图片
template下创建fm模块。文件夹下再见user模块
技术分享图片

技术分享图片
controller
技术分享图片

技术分享图片

启动应用
技术分享图片
在模板里面显示配置文件的配置参数。记住最上面要加上@Component注解
技术分享图片

ModelMap就是LinkedHashMap
技术分享图片
技术分享图片
第二个参数是一个Object类型的
技术分享图片

技术分享图片

模板里面取值
技术分享图片

技术分享图片

语法可以自己百度去查
技术分享图片


技术分享图片

 

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

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

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