springboot集成模板引擎freemarker和thymeleaf
freemarkder和thymeleaf都是java的模板引擎,这里只介绍这两种模板引擎如何在sprongboot中配置:
1. freemarkder
1.1 在pom.xml中添加依赖包
<!-- 集成freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
1.2 在配置文件application.properties中添加配置
# ================================================
# FreeMarker配置
# ================================================
# 是否开启模板缓存
spring.freemarker.cache=true
# 编码格式
spring.freemarker.charset=UTF-8
# 模板的媒体类型设置
spring.freemarker.content-type=text/html
# 前缀设置 默认为 ""
spring.freemarker.prefix=
# 后缀设置 默认为 .ftl
spring.freemarker.suffix=.ftl
#spring.freemarker.allow-request-override=false
#spring.freemarker.check-template-location=true
#spring.freemarker.expose-request-attributes=false
#spring.freemarker.expose-session-attributes=false
#spring.freemarker.expose-spring-macro-helpers=false
#spring.freemarker.request-context-attribute=
#spring.freemarker.template-loader-path=classpath:/templates/
#spring.freemarker.view-names=
2. thymeleaf
2.1 在pom.xml中添加依赖包
<!-- 集成thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.2 添加配置文件
# ================================================
# Thymeleaf配置
# ================================================
# 是否启用thymeleaf模板解析
spring.thymeleaf.enabled=true
# 是否开启模板缓存(建议:开发环境下设置为false,生产环境设置为true)
spring.thymeleaf.cache=false
# Check that the templates location exists.
spring.thymeleaf.check-template-location=true
# 模板的媒体类型设置,默认为text/html
spring.thymeleaf.content-type=text/html
# 模板的编码设置,默认UTF-8
spring.thymeleaf.encoding=UTF-8
# 设置可以被解析的视图,以逗号,分隔
#spring.thymeleaf.view-names=
# 排除不需要被解析视图,以逗号,分隔
#spring.thymeleaf.excluded-view-names=
# 模板模式设置,默认为HTML5
#spring.thymeleaf.mode=HTML5
# 前缀设置,SpringBoot默认模板放置在classpath:/template/目录下
spring.thymeleaf.prefix=classpath:/templates/
# 后缀设置,默认为.html
spring.thymeleaf.suffix=.html
# 模板在模板链中被解析的顺序
#spring.thymeleaf.template-resolver-order=
springboot集成模板引擎freemarker和thymeleaf的更多相关文章
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- 【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf
========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf ========================= 1.SpringBoot Sta ...
- SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课
1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
- springboot:Java模板引擎Thymeleaf介绍
Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用 ...
- 实现一个代码自动生成(一):模板引擎Freemarker
目录 前言 模板引擎FreeMarker 前言 在现在的开发当中,代码生成已经是必不可少的一个功能,每个公司都会有自己的一套定制的项目骨架,而实现代码自动生成,模板引擎是必不可少的,所以在这篇博客中, ...
- Java模板引擎Freemarker
Java模板引擎Freemarker 1.取值(插值)指令 2.逻辑指令:if.switch 3.字符串.集合操作 4.自定义函数 5.list排序内建函数.常用指令 6.自定义指令 7.freema ...
- SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)
SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...
- SpringBoot系列:Spring Boot使用模板引擎FreeMarker
一.Java模板引擎 模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. 在jav ...
- Spring Boot (三)模板引擎FreeMarker集成
一.FreeMaker介绍 FreeMarker是一款免费的Java模板引擎,是一种基于模板和数据生成文本(HMLT.电子邮件.配置文件.源代码等)的工具,它不是面向最终用户的,而是一款程序员使用的组 ...
随机推荐
- C# DataGridView在单元格提示里(ToolTip)显示完整的单元格内容
当单元格内容太多时,则会忽略后面的内容 解决方案: 添加Dgv鼠标移到单元格事件时,设置当前单元格的ToolTipText属性内容为当前单元格内容 void From_Load(object send ...
- 如何快速访问MSDN某一个类或方法的帮助文档
如何快速访问MSDN某一个类或方法的帮助文档? 我一般都是在Google上搜索的如"string msdn",而不是在Msdn上直接查找(你不可能知道所有的类或方法的完整命名空间) ...
- 利用html5调用本地摄像头拍照上传图片[转]
利用html5调用本地摄像头拍照上传图片 html5概念啥的就不废话了,不知道的 百度, 谷歌一堆..今天学了学html5中的Canvas结合新增的<video>标签来获取本地摄像头, ...
- VMware Workstation的网络连接方式:NAT、桥接和Host Only
安装完VMware Workstation后会自动生成两个网络连接:VMware Network Adapter VMnet8 和 VMware Network Adapter VMnet1(通常称为 ...
- model中设置默认值时 ,使用 lambda 与否的差别以及datetime的默认值方法
'date': '2013-01-01' #固定值 'date': time.strftime('%Y-%m-%d') #启动时候的值 'date': lambda *a: time.strfti ...
- phpredis中文手册——《redis中文手册》 php版(转)
redis中文手册:http://readthedocs.org/docs/redis/en/latest/ 本文是参考<redis中文手册>,将示例代码用php来实现,注意php-red ...
- Linux 内核源码情景分析 chap 2 存储管理 (四)
物理页面的使用和周转 1. 几个术语 1.1 虚存页面 指虚拟地址空间中一个固定大小, 边界与页面大小 4KB 对齐的区间及其内容 1.2 物理页面 与虚存页面相对的, 须要映射到某种物理存储介质上面 ...
- 【apache2】apache2查看错误日志、请求日志
1.一般存储路径在 [ /var/log/apache2/ ]下面, 2.错误日志和请求日志 必须要进行定期清理. 清理完成后,必须重启apache [ cd / ; service apac ...
- ubuntu建立软ap共享无线网络
建立ad-hoc模式共享网络 viewtopic.php?f=116&t=387194 有些android手机可能不支持ad-hoc模式,要第三方rom才行. 首先安装这些工具 代码: apt ...
- 一招破解混淆后的JavaScript代码
http://www.cnblogs.com/zjyuan/archive/2011/12/14/2287647.html JavaScript不是很给力,想怎么破解就怎么破解!此文章教你的不仅仅是破 ...