zoukankan      html  css  js  c++  java
  • springboot(7)springboot整合freemarker和thymeleaf

    Springboot整合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

    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=HTML
    #前缀
    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

  • 相关阅读:
    Mycat分布式数据库&.NET链接mysql
    MySQL安装
    Apache 安装配置及开启PHP模块支持
    XSS MSMQ FASTDFS RABBITMQ
    json表单回填(表单反序列化回填值)
    解决80端口被占用
    Oracle for .net & ServiceStack.OrmLite
    MBTiles 离线地图演示
    Java网络编程TCP程序,服务器和客户机交互流程以及基本操作步骤。
    如何使用和理解java的反射机制
  • 原文地址:https://www.cnblogs.com/suncm/p/10907438.html
Copyright © 2011-2022 走看看