SpringBoot集成freemarker和thymeleaf模板
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模板的更多相关文章
- springboot之freemarker 和thymeleaf模板web开发
Spring Boot 推荐使用Thymeleaf.FreeMarker.Velocity.Groovy.Mustache等模板引擎.不建议使用JSP. 一.Spring Boot 中使用Thymel ...
- SpringBoot集成Freemarker与Thymeleaf
一:概括 pom.xml添加依赖 配置application.yml HTML页面使用表达式 二:Freemarker模板引擎 1.添加依赖 <!-- ftl模板引擎 --> <de ...
- SpringBoot 集成 FreeMarker 导出 Word 模板文件(底部附源码)
思路解说 word 模板文件(doc 或 docx 文件)另存为 xml 文件 将后缀 xml 改成 html:大部分文档会改成 ftl(FreeMarker 的后缀名),因为 word 文件另存为 ...
- SpringBoot Web开发(4) Thymeleaf模板与freemaker
SpringBoot Web开发(4) Thymeleaf模板与freemaker 一.模板引擎 常用得模板引擎有JSP.Velocity.Freemarker.Thymeleaf SpringBoo ...
- Springboot集成FreeMarker
Apache官网对FreeMarker的解释如下: Apache FreeMarker™是一个模板引擎 :一个基于模板和变化的数据来生成文本输出(HTML网页,电子邮件,配置文件,源代码,等等)的Ja ...
- SpringBoot入门篇--使用Thymeleaf模板引擎进行页面的渲染
在做WEB开发的时候,我们不可避免的就是在前端页面之间进行跳转,中间进行数据的查询等等操作.我们在使用SpringBoot之前包括我在内其实大部分都是用的是JSP页面,可以说使用的已经很熟悉.但是我们 ...
- springboot 集成 freemarker
前面我们已经实现了thymeleaf模板,其实freemarker和thymeleaf差不多,都可以取代JSP页面,实现步骤也差不多,我们来简单实现一下 引入pom.xml依赖如下 <depen ...
- SpringBoot学习笔记(4)----SpringBoot中freemarker、thymeleaf的使用
1. freemarker引擎的使用 如果你使用的是idea或者eclipse中安装了sts插件,那么在新建项目时就可以直接指定试图模板 如图: 勾选freeMarker,此时springboot项目 ...
- springboot笔记06——使用Thymeleaf模板引擎
前言 Springboot 推荐使用Thymeleaf做视图层.Thymeleaf支持 html 原型,然后在 html 标签里增加额外的属性来达到模板+数据的展示方式.浏览器解释 html 时会忽略 ...
随机推荐
- VS2010 无法启动程序,系统找不到指定的文件
1>------ 已启动生成: 项目: work, 配置: Debug Win32 ------1>生成启动时间为 2018/1/9 14:01:16 下午.1>Initialize ...
- WebApi和Andriod对接访问模式问题
最近在做WebApi和Andriod接口的对接,中途出现一个问题就是返回格式的问题.由于之前使用WebService的时候使用的一直都是json的序列化和反序列话格式,所以一开始在webapi中通样使 ...
- linux tcp server demo
#include <sys/types.h> #include <sys/socket.h> #include <string.h> #include <ne ...
- python解析时间格式脚本
对于这种时间格式:發表於: 星期一 五月 28, 2012 6:59 am import re INPUT = "發表於: 星期一 五月 28, 2012 6:59 am 文章主題: 對&l ...
- 卷积神经网络之AlexNet网络模型学习
ImageNet Classification with Deep Convolutional Neural Networks 论文理解 在ImageNet LSVRC-2010上首次使用大型深度卷 ...
- 【学习笔记】dp基础
知识储备:dp入门. 好了,完成了dp入门,我们可以做一些稍微不是那么裸的题了. dp基础,主要是做题,只有练习才能彻底掌握. 洛谷P1417 烹调方案 分析:由于时间的先后会对结果有影响,所以c[i ...
- IBM AIX创建lv
#lsvg 查看当前有哪些vgrootvgvgdb02vgdb01datavg#lslv maindb_index 查看maindb_index这个lv 位于哪个vg上,新的lv也要与之相同.LOGI ...
- 关于Spring的Quartz的xml配置的例子
<span style="font-size:16px"></span><h3><span style="font-family ...
- WebService与WCF
5.Web Service和WCF的到底有什么区别 https://zhidao.baidu.com/question/1368120490988718179.html 6.VS 2010中使用C#创 ...
- sysbench基准测试(2)——oltp.lua测试
前面知道sysbench基准测试的主要步骤为:prepare(准备数据集)→ run(运行测试)→ cleanup(清除数据集) 这一节介绍oltp.lua测试. oltp基准测试模拟了一个简单的事物 ...