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 时会忽略 ...
随机推荐
- logcat调试系统
日志存放位置:/dev/log shell@xxx:/ $ ls /dev/log -l crw-rw-rw- root log , -- : events crw-rw-rw- root log , ...
- 干货:这也许是最全面透彻的一篇RabbitMQ指南!
本文大纲: RabbitMQ 历史 RabbitMQ 应用场景 RabbitMQ 系统架构 RabbitMQ 基本概念 RabbitMQ 细节阐明 历史-从开始到现在 RabbitMQ是一个Erlan ...
- idea 类注释,方法注释设置
类头注释:打开file->setting->Editor->Filr and Code Templates->Includes->File Header 直接在右边的文件 ...
- H5测试 有空了解下里面没有用过的东西
- 028:基于mysqldump备份脚本
MySQL Backup and Recovery 一 MySQL Backup 1.功能 mysqldump全量和增量备份,通过最近一次备份刷新产生binlog来定位执行增量. 脚本下载地址 git ...
- setTimeout和setInterval的unref()和ref()用法
var testFunction=function(){ console.log("guoyansi"); } var timer=setInterval(testFunction ...
- Linux无法登录,显示module is unknown,一闪而过
1.使用单用户模式登录系统(不作介绍) 2.查看日志:vim /var/log/secure 3.记忆起曾经配置oracle添加过该参数 vim/etc/pam.d/login中加入了: sessio ...
- 几个常用的Linux监控脚本
几个常用的Linux监控脚本 几个常用的Linux监控脚本下面是几个主机监控的脚本,大家可以根据自己的情况再进行修改,希望能给大家一点帮助.1.查看主机网卡流量#!/bin/bash#network# ...
- html中的响应式图片
html中的响应式图片 img sizes 指定屏幕尺寸 srcset 指定可以使用的图片和大小,多个使用逗号分隔,需要指定图片的真实宽度,个人觉得没有picture好用 <img sizes= ...
- pycharm多行代码同时注释、去除注释
pycharm中同时注释多行代码快捷键: 代码选中的条件下,同时按住 Ctrl+/,被选中行被注释,再次按下Ctrl+/,注释被取消