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




    模板里面取值




    语法可以自己百度去查





     

  • 相关阅读:
    python学习第十一天 -- 函数式编程
    python学习第十天 -- 函数
    python学习第九天 -- 列表生产式
    python学习第八天 -- 迭代
    (转载)C# 编程 使用可空类型
    Func的介绍——c#封装的代理
    select SCOPE_IDENTITY()用法
    insert into 语句的三种写法
    面试感悟----一名3年工作经验的程序员应该具备的技能
    SQL中常用模糊查询的四种匹配模式&&正则表达式
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11421755.html
Copyright © 2011-2022 走看看