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

    笔记

    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类型的




    模板里面取值




    语法可以自己百度去查





     

  • 相关阅读:
    文件操作相关utils
    读取excel工具utils
    下载EXCEL文件Utils
    日期操作utils
    常用的utils
    坐标系转换Utils
    C# vs2019 CS0006 编译器错误CS1704
    C# 控制台形式 owin 添加WebApi 和Swagger
    Windows 下 Redis服务自动停止 处理
    Dotfuscator 混淆C# .Net代码 netcore
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11421755.html
Copyright © 2011-2022 走看看