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=

原文地址:https://www.cnblogs.com/30go/p/8439261.html

时间: 2024-08-09 19:27:45

springboot中添加模板引擎freemarker和thymeleaf的相关文章

小D课堂【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf

========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf 4节课========================= 1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#using-boot-starter

Spring Boot 整合模板引擎 Freemaker、thymeleaf

1.常用的 Spring Boot 2.x 模板引擎和官方推荐案例 1)JSP(后端渲染,消耗性能) Java Server Pages 动态网页技术,由应用服务器中的 JSP 引擎来编译和执行,再将生成的整个页面返回给客户端.优点是:可以写java代码.支持表达式语言(el.jstl).内建函数. 但 JSP 本质上是 Servlet,它非常占用 JVM 内存.Java Web 官方推荐,但 Spring Boot 不推荐https://docs.spring.io/spring-boot/d

springBoot(5):web开发-模板引擎FreeMarker

一.简介 spring boot的web应用开发,是基于spring mvc. Spring boot在spring默认基础上,自动配置添加了以下特性: 1.包含了ContentNegotiatingViewResolver和BeanNameViewResolver beans. 2.对静态资源的支持,包括对WebJars的支持. 3.自动注册Converter,GenericConverter,Formatter beans. 4.对HttpMessageConverters的支持. 5.自动

springboot整合thymleaf模板引擎

thymeleaf作为springboot官方推荐使用的模板引擎,简单易上手,功能强大,thymeleaf的功能和jsp有许多相似之处,两者都属于服务器端渲染技术,但thymeleaf比jsp的功能更强大. 1. thymeleaf入门 1.1 引入坐标 <!--springBoot整合thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>

Java模板引擎 FreeMarker

概念 FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写. 它是为Java程序猿提供的一个开发包.它不是面向终于用户的,而是为程序猿提供的一款能够嵌入他们所开发产品的应用程序. 介绍 那么.FreeMarker是一款如何的工具呢?FreeMarker实际上是被设计用来生成HTML Web页面,尤其是通过实现了基于MVC模式的Java Servlet应用程序.使用MVC模式的动态页面的设计构思使得你能够将前端设计师从程序猿中分离出来.全部人各司其职,发挥其最

Spring Boot基础6-web应用开发-模板引擎FreeMarker

原文视频参考:http://www.roncoo.com/course/view/c99516ea604d4053908c1768d6deee3d 一.spring boot的web应用开发,是基于spring mvc 二.Spring boot 在spring默认基础上,自动配置添加了以下特性: 1.   包含了ContentNegotiatingViewResolver和BeanNameViewResolver beans. 2.   对静态资源的支持,包括对WebJars的支持. 3.  

「快学springboot」SpringBoot整合freeMark模板引擎

前言 虽然现在流行前后端分离开发和部署,但是有时候还是需要用到服务端渲染页面的.比如:需要考虑到SEO优化等问题的时候,FreeMark其实还是很有作用的.本人的博客本来是用React开发的,但是后来发现搜索引擎难以收集由JS渲染的页面,所以前段时间,是用jQuery+FreeMark重写了我的博客前端页面.感兴趣的朋友,可以点击下面的查看更多的链接跳转至本人的博客. 在springboot中,不推荐使用JSP(其实任何项目都不推荐使用JSP),而是推荐使用模板引擎,如FreeMark.其实使用

在Express中使用模板引擎

定义模板引擎 var app = express(); app.set('views', './views'); // 指定模板文件存放位置 app.set('view engine', 'jade') // 设置默认的模板引擎 注册指定扩展名的模板引擎: app.engine('jade', require('jade')._express ) 注意: _express函数是许多模板引擎提供的回调函数.但是这个函数只能在默认的文件扩展名上工作.但是,有种情况我们使用的不是对应模板引擎的扩展名的

nodejs学习(二) ---- express中使用模板引擎jade

系列教程,上一节教程  express+nodejs快速创建一个项目 在创建一个项目后,views目录下的文件后缀为 .jade . 打开 index.jade,具体内容如下图(忽略 header.jade 和 footer.jade,下面教程会一步步创建) 页面解析出的样子如下图.完全是html标签 一.jade 模板引擎 介绍 模板引擎是一个库,或者一个使用一定的规则或者语言来解释数据并渲染视图的框架.模板引擎处理过的最终结果是一个视图页面,也就是html页面或者用户图形界面GUI.在MVC