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




    模板里面取值




    语法可以自己百度去查





     

  • 相关阅读:
    遮罩
    css3 transform
    jq图片懒加载
    transition
    css3动画
    div水平垂直居中的方法
    一行文字的时候,文字在整个盒子中垂直水平居中,超过一行之后,文字在盒子中垂直水平居中,文字左对齐
    10个你可能没用过的Linux命令
    sed命令详解
    linux中的快捷键汇总
  • 原文地址:https://www.cnblogs.com/wangjunwei/p/11421755.html
Copyright © 2011-2022 走看看