SpringBoot2.1.5(33)---SpringBoot整合 Thymeleaf 模板引擎
目录
- 一、 Thymeleaf
- 简介:
- 官网
- 官方文档
- 入门资料参考:
- 二、代码实践
- 1、maven依赖
- 2、yml 文件 配置
- 3、Thymeleaf 文件
- 4、测试Controller
- 5、启动项目,进行测试
一、 Thymeleaf
简介:
Thymeleaf是用于Web和独立环境的现代服务器端Java模板引擎。
Thymeleaf的主要目标是将优雅的自然模板带到您的开发工作流程中—HTML能够在浏览器中正确显示,并且可以作为静态原型,从而在开发团队中实现更强大的协作。Thymeleaf能够处理HTML,XML,JavaScript,CSS甚至纯文本。
Thymeleaf的主要目标是提供一个优雅和高度可维护的创建模板的方式。 为了实现这一点,它建立在自然模板的概念之上,以不影响模板作为设计原型的方式将其逻辑注入到模板文件中。 这改善了设计沟通,弥合了前端设计和开发人员之间的理解偏差。
Thymeleaf也是从一开始就设计(特别是HTML5)允许创建完全验证的模板。
官网
https://www.thymeleaf.org/
官方文档
https://www.thymeleaf.org/documentation.html
入门资料参考:
https://blog.csdn.net/zrk1000/article/details/72667478
二、代码实践
1、maven依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
2、yml 文件 配置
server:port: 8081spring:application:name: thymeleafthymeleaf:# 是否启用模板缓存。cache: true# 是否检查模板位置是否存在。check-template: true# 是否为Web框架启用Thymeleaf视图分辨率。enabled: true# 编码格式, 默认UTF-8encoding: UTF-8# 应用于模板的模板模式。另请参阅Thymeleaf的TemplateMode枚举。mode: HTML# 后缀 默认 .htmlsuffix: .html# 模板文件存放位置 , 默认 classpath:/templates/prefix: classpath:/templates/
3、Thymeleaf 文件
创建 模板文件 index.html,文件内容如下
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1 th:text="${content}"></h1>
</body>
</html>
4、测试Controller
/*** created with IntelliJ IDEA.* author: fxbin* date: 2018/10/21* time: 4:42* version: 1.0* description:*/
@Controller
public class ThymeleafController {@RequestMapping("/test")public String test(Model model){model.addAttribute("content", "Hello Thymeleaf");return "index";}
}
5、启动项目,进行测试
访问 http://localhost:8081/test , 可以看到我们设置在controller 中的内容成功显示在了页面上
SpringBoot2.1.5(33)---SpringBoot整合 Thymeleaf 模板引擎相关推荐
- SpringBoot整合Thymeleaf模板引擎以及静态资源的访问
SpringBoot整合Thymeleaf模板引擎静态资源访问的配置 Thymeleaf是一个现代服务器端Java模板引擎,适用于Web和独立环境,能够处理HTML,XML,JavaScript,CS ...
- SpringBoot2.1.5 (32)--- SpringBoot整合 Freemaker 模板引擎
一.Freemarker 1.maven 依赖: 2.yml 文件配置: 3.创建Freemarker模板文件 4.创建测试Controller 5.启动项目,进行测试 一.Freemarker 简介 ...
- 【Springboot】SpringBoot基础知识及整合Thymeleaf模板引擎
文章目录 SpringBoot简介 SpringBoot是什么 为什么要学习SpringBoot SpringBoot的优势 学习SpringBoot前要具备的基础 创建第一个SpringBoot项目 ...
- Springboot整合thymeleaf模板
Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用. Thymeleaf的主要目标在于提供一种可被浏览器正确显示的.格式良好的模板创建方式,因此也可以用作静态建 ...
- Spring Boot整合Thymeleaf模板引擎
转载自 Spring Boot整合Thymeleaf模板引擎 什么是Thymeleaf Thymeleaf是一款用于渲染XML.XHTML.HTML5内容的模板引擎.类似Velocity,FreeMa ...
- 【SpringBoot】3、SpringBoot中整合Thymeleaf模板引擎
SpringBoot 为我们提供了 Thymeleaf 自动化配置解决方案,所以我们在 SpringBoot 中使用 Thymeleaf 非常方便 一.简介 Thymeleaf是一个流行的模板引擎,该 ...
- java 模板引擎_SpringBoot入门系列(四)如何整合Thymeleaf模板引擎
前面介绍了Spring Boot的优点,然后介绍了如何快速创建Spring Boot 项目.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/ ...
- java 模板引擎_Spring Boot 如何快熟整合Thymeleaf模板引擎
前面介绍了Spring Boot的优点,然后介绍了如何快速创建Spring Boot 项目.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/ ...
- 玩转springboot:thymeleaf模板引擎入门程序
一.前言 常用的模板引擎有:JSP.Velocity.Freemarker.Thymeleaf 但是,Springboot默认是不支持JSP的,默认使用thymeleaf模板引擎.而且,语法更简单,功 ...
最新文章
- 噪声与平滑滤波(MATLAB)
- 组合模式——透明组合模式,安全组合模式
- ***学习笔记教程五:***技术
- c语言二维数组赋值前面是行还是列,动态二维数组分配有问题啊 为什么行和列相同才能给数组赋值...
- 国内ios分亨组件,
- python定时任务,隔月执行,隔定时执行
- linux 脚本追加最后命令,linux中sed命令批量修改
- 开课吧9.9元学python靠谱吗-开课吧的Python课程怎么样?大概是多少钱?讲师是廖雪峰吗?...
- python自动化_Python 接口自动化
- 易语言webservice接口_易语言webservice接口调用助
- 第五章、SQL 语言学习(基础篇)
- 火星坐标 C语言,iOS7上地球坐标系到火星坐标系转换算法
- 解决“桌面右键单击文件夹鼠标一直转圈”
- 猫哥教你写爬虫 034--爬虫-BeautifulSoup实践
- 练习题 斐波那契数列
- R语言实现单因素方差分析
- 通过封装接口拿到淘宝店铺订单,淘宝店铺订单解密接口,淘宝店铺订单明文接口,天猫店铺订单明文接口代码展示
- 400+考研 北京航空航天大学6系计算机学院961计算机专业技术基础资料合辑
- 归并排序算法代码实现
- 如何减少http请求