欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

springBoot加入thymeleaf模板的方式

时间:2021-09-13 08:01:01|栏目:JAVA代码|点击:

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

在这里插入图片描述

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

常用标签介绍

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

上一篇:Spring实战之Bean定义中的SpEL表达式语言支持操作示例

栏    目:JAVA代码

下一篇:spring mvc实现登录账号单浏览器登录

本文标题:springBoot加入thymeleaf模板的方式

本文地址:http://www.codeinn.net/misctech/174638.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有