• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

springBoot加入thymeleaf模板的方式

springboot 搞代码 4年前 (2022-01-09) 16次浏览 已收录 0个评论

1.新建springBoot项目

在前面有两种方式

2.加入thymeleaf模板引擎

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

<de<strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码*网/</strong>pendency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

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

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

4.运行,然后访问项目

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

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

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

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

把数据放在controller的map中

前端通过标签取出数据

显示效果

6.thymeleaf标签语法

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

常用标签介绍

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:springBoot加入thymeleaf模板的方式

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址