如何通过SpringBoot集成thymeleaf模板引擎?

2026-05-16 05:232阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计344个文字,预计阅读时间需要2分钟。

如何通过SpringBoot集成thymeleaf模板引擎?

1. 新建SpringBoot项目+方式:目前有两种方式

2.添加thymeleaf模板引擎+推荐:SpringBoot推荐使用thymeleaf模板引擎,语法简单,功能强大

想要引入thymeleaf,只需在pom.xml文件中添加以下依赖即可:`org.springframework.bootspring-boot-starter-thymeleaf`

1.新建springBoot项目

在前面有两种方式

2.加入thymeleaf模板引擎

SpringBoot推荐使用thymeleaf模板引擎
语法简单,功能更强大
要想引入thymeleaf,只需要在pom,xml文件中加入如下依赖就可以了

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

3.在controller中定义跳转的页面

会自动去templates文件夹下去找index.html

如何通过SpringBoot集成thymeleaf模板引擎?

4.运行,然后访问项目

输入localhost:8080/testThymeleaf即可访问index.html

5.在html页面中加入thymeleaf模板标签所需的命名空间

<!DOCTYPE html> <html lang="en" xmlns:th="www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>测试thymeleaf模板</title> </head> <body> 欢迎来到测试thymeleaf界面 </body> </html>

6.将controller数据通过thymeleaf标签传到前端界面

把数据放在controller的map中

前端通过标签取出数据

显示效果

6.thymeleaf标签语法

官方文档
www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf
thymeleaf中文
raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html

常用标签介绍


到此这篇关于springBoot加入thymeleaf模板的方式的文章就介绍到这了,更多相关springBoot thymeleaf模板内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签:

本文共计344个文字,预计阅读时间需要2分钟。

如何通过SpringBoot集成thymeleaf模板引擎?

1. 新建SpringBoot项目+方式:目前有两种方式

2.添加thymeleaf模板引擎+推荐:SpringBoot推荐使用thymeleaf模板引擎,语法简单,功能强大

想要引入thymeleaf,只需在pom.xml文件中添加以下依赖即可:`org.springframework.bootspring-boot-starter-thymeleaf`

1.新建springBoot项目

在前面有两种方式

2.加入thymeleaf模板引擎

SpringBoot推荐使用thymeleaf模板引擎
语法简单,功能更强大
要想引入thymeleaf,只需要在pom,xml文件中加入如下依赖就可以了

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>

3.在controller中定义跳转的页面

会自动去templates文件夹下去找index.html

如何通过SpringBoot集成thymeleaf模板引擎?

4.运行,然后访问项目

输入localhost:8080/testThymeleaf即可访问index.html

5.在html页面中加入thymeleaf模板标签所需的命名空间

<!DOCTYPE html> <html lang="en" xmlns:th="www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>测试thymeleaf模板</title> </head> <body> 欢迎来到测试thymeleaf界面 </body> </html>

6.将controller数据通过thymeleaf标签传到前端界面

把数据放在controller的map中

前端通过标签取出数据

显示效果

6.thymeleaf标签语法

官方文档
www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf
thymeleaf中文
raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html

常用标签介绍


到此这篇关于springBoot加入thymeleaf模板的方式的文章就介绍到这了,更多相关springBoot thymeleaf模板内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

标签: