1、在MAVEN工程POM.XML中引入依赖架包

<!-- 引入 freemarker 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- 引入 thymeleaf 模板依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、在属性系统配置文件中application.properties 加入相关配置

############################################################
#
# freemarker 静态资源配置
#
############################################################
#设定ftl文件路径
spring.freemarker.template-loader-path=classpath:/templates
# 关闭缓存, 即时刷新, 上线生产环境需要改为true
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
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.request-context-attribute=request
spring.freemarker.suffix=.ftl

############################################################
#
# thymeleaf 静态资源配置
#
############################################################
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
# 关闭缓存, 即时刷新, 上线生产环境需要改为true
spring.thymeleaf.cache=false

3、具体的Controller实体类中需要注解

如:FreemarkerController.java

 package com.leecx.controller;

 import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/ftl")
public class FreemarkerController { @RequestMapping("/freemaker")
public String index(ModelMap modelMap){
modelMap.put("name", "duanml");
return "freemarker/index";
} @RequestMapping("/center")
public String center(ModelMap modelMap){
modelMap.put("name", "duanml");
return "freemarker/center/center";
}
}

如:ThymeleafController.java

 package com.leecx.controller;

 import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/th")
public class ThymeleafController { @RequestMapping("/thymeleaf")
public String index(ModelMap modelMap){
modelMap.put("name", "duanml");
return "thymeleaf/index";
} @RequestMapping("/center")
public String center(ModelMap modelMap){
modelMap.put("name", "duanml");
return "thymeleaf/center/center";
}
}

4、在项目的工程中静态资源建立如下的层级关系:

注意freemarker和thymeleaf  两者的静态页面的后缀是不一样的。

SpringBoot集成freemarker和thymeleaf模板的更多相关文章

  1. springboot之freemarker 和thymeleaf模板web开发

    Spring Boot 推荐使用Thymeleaf.FreeMarker.Velocity.Groovy.Mustache等模板引擎.不建议使用JSP. 一.Spring Boot 中使用Thymel ...

  2. SpringBoot集成Freemarker与Thymeleaf

    一:概括 pom.xml添加依赖 配置application.yml HTML页面使用表达式 二:Freemarker模板引擎 1.添加依赖 <!-- ftl模板引擎 --> <de ...

  3. SpringBoot 集成 FreeMarker 导出 Word 模板文件(底部附源码)

    思路解说 word 模板文件(doc 或 docx 文件)另存为 xml 文件 将后缀 xml 改成 html:大部分文档会改成 ftl(FreeMarker 的后缀名),因为 word 文件另存为 ...

  4. SpringBoot Web开发(4) Thymeleaf模板与freemaker

    SpringBoot Web开发(4) Thymeleaf模板与freemaker 一.模板引擎 常用得模板引擎有JSP.Velocity.Freemarker.Thymeleaf SpringBoo ...

  5. Springboot集成FreeMarker

    Apache官网对FreeMarker的解释如下: Apache FreeMarker™是一个模板引擎 :一个基于模板和变化的数据来生成文本输出(HTML网页,电子邮件,配置文件,源代码,等等)的Ja ...

  6. SpringBoot入门篇--使用Thymeleaf模板引擎进行页面的渲染

    在做WEB开发的时候,我们不可避免的就是在前端页面之间进行跳转,中间进行数据的查询等等操作.我们在使用SpringBoot之前包括我在内其实大部分都是用的是JSP页面,可以说使用的已经很熟悉.但是我们 ...

  7. springboot 集成 freemarker

    前面我们已经实现了thymeleaf模板,其实freemarker和thymeleaf差不多,都可以取代JSP页面,实现步骤也差不多,我们来简单实现一下 引入pom.xml依赖如下 <depen ...

  8. SpringBoot学习笔记(4)----SpringBoot中freemarker、thymeleaf的使用

    1. freemarker引擎的使用 如果你使用的是idea或者eclipse中安装了sts插件,那么在新建项目时就可以直接指定试图模板 如图: 勾选freeMarker,此时springboot项目 ...

  9. springboot笔记06——使用Thymeleaf模板引擎

    前言 Springboot 推荐使用Thymeleaf做视图层.Thymeleaf支持 html 原型,然后在 html 标签里增加额外的属性来达到模板+数据的展示方式.浏览器解释 html 时会忽略 ...

随机推荐

  1. MFC对话框的Edit控件实现响应Ctrl+A全选,并实现自动/手动换行+滚动条

    首先是在Properties中设置控件属性的问题,首先必须得将Mutilines属性设为true,才能支持多行显示. 手动换行(按Enter键换行):将Want Return属性设为true 自动换行 ...

  2. 【Leetcode 371】Sum of Two Integers

    问题描述:不使用+是或-操作符进行整数的加法运算 int getSum(int a, int b); 我的思路:把整数化成二进制进行运算,注意类型是int,也就是要考虑负数.关于负数的二进制表示可见之 ...

  3. 汇编_指令_CS与DS的区别

    cs是值cpu执行的当前指令的段地址,ds是数据开始的段地址. CS是告诉CPU,去哪个位置找内容当成指令去执行:DS是告诉CPU,去哪个位置找内容当成数据被使用. datastring =ds co ...

  4. mysql 优化(2)

    --cfq,deadline,noop--radi10,xfs,ext4--innodb_flush_log_at_trx_commit=0/1/2--sys_binlog=1/n CPU的利用特点• ...

  5. ApacheOFBiz的相关介绍以及使用总结(一)

    由于最近一段时间在给一个创业的公司做客户关系管理CRM系统,限于人力要求(其实是没有多少人力),只能看能否有稳定,开源的半成品进行改造,而且最好不需要前端(js)相关开发人员的支援就可以把事情做成,经 ...

  6. 简单IOCP例子

    使用IOCP模型编程的优点 ① 帮助维持重复使用的内存池.(与重叠I/O技术有关) ② 去除删除线程创建/终结负担. ③ 利于管理,分配线程,控制并发,最小化的线程上下文切换. ④ 优化线程调度,提高 ...

  7. 导出ExcelDemo

    public String exportExcel(){ String message=null; SimpleDateFormat df =new SimpleDateFormat("yy ...

  8. 生成html页面客户端随机数和验证码

    生成随机数: var chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', ...

  9. thymeleaf switch在表格中的使用,遇到的空行问题

    switch在表格中的使用时 如果把<td>写在<div th:switch="${data.isShow}"> 里面导致外面出现很多空的<div&g ...

  10. Cesium有价值网址

    //比较粗 https://www.cnblogs.com/mazhenyu/p/6494748.html //很详细 2019.4.19 https://www.cnblogs.com/fuckgi ...