热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

springBoot加入thymeleaf模板的方式

这篇文章主要介绍了springBoot加入thymeleaf模板的方式,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

1.新建springBoot项目

在前面有两种方式

2.加入thymeleaf模板引擎

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

在这里插入图片描述


   org.springframework.boot
   spring-boot-starter-thymeleaf

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

在这里插入图片描述

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

在这里插入图片描述

4.运行,然后访问项目

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

在这里插入图片描述

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

在这里插入图片描述




  
  


欢迎来到测试thymeleaf界面

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模板内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


推荐阅读
author-avatar
alxg
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有