Thymeleaf是什么?该如何使用。
使用只需要在前端页面注意这个就行了,html标签里面加上: xmlns:th="http://www.thymeleaf.org
<html lang="en" xmlns:th="http://www.thymeleaf.org">
然后就可以使用了
然后举个例子
<h1 th:text="${'隔壁老王'}">法外狂徒张三</h1>
‘隔壁老王’ 这个地方可以使用占位符,我这样写比较直观
2.Thymeleafi 简单表达式:
- 变量表达式:${....}
- 选变量表达式:*{....}
- 消息表达式:#{....}
- 链接网址表达式:@{....}
- 片段表达式:~{....}
<!--thymeleaf依赖-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>

| 标签属性 | 功能描述 | 示例 |
|---|---|---|
| th:id | 替换id | <input th:id="'xxx' + ${collect.id}"/> |
| th:text | 文本替换 | <p th:text="${collect.description}">description</p> |
| th:utext | 支持html的文本替换 | <p th:utext="${htmlcontent}">content</p> |
| th:object | 替换对象 | <div th:object="${session.user}"> |
| th:value | 属性赋值 | <input th:value = "${user.name}" /> |
| th:with | 变量赋值运算 | <div th:with="isEvens = ${prodStat.count}%2 == 0"></div> |
| th:style | 设置样式 | <div th:style="'display:' + @{(${sitrue} ? 'none' : 'inline-block')} + ''"></div> |
| th:onclick | 点击事件 | <td th:onclick = "'getCollect()'"></td |
| th:each | 属性赋值 | <tr th:each = "user,userStat:${users}"> |
| th:if | 判断条件 | <a th:if = "${userId == collect.userId}"> |
| th:unless | 和th:if判断相反,满足条件时不显示 | <a th:href="@{/login} th:unless=${session.user != null}">Login</a> <!--如果用户已登录,则不显示登录按钮--> |
| th:href | 链接地址 | <a th:href="@{/login}" th:unless=${session.user != null}>Login</a> |
| th:switch | 多路选择,配合th:case使用 | <div th:switch="${user.role}"> |
| th:fragment | 模板布局,类似jsp的tag | <div th:fragment="footer">© 2013 Footer</div> |
| th:include | 布局标签,替换内容到引入的文件 | <head th:include="layout :: htmlhead" th:with="title='xx'"></head> |
| th:replace | 布局标签,替换整个标签到引入的文件 | <div th:replace="fragments/header :: title"></div> |
| th:selected | select选择框选中 | th:selected="(${xxx.id} == ${configObj.dd})" |
| th:src | 图片类地址引入 | <img class="img-responsive" alt="App Logo" th:src="@{/img/logo.png}" /> |
| th:inline | 定义js脚本可以使用变量 | <script type="text/javascript" th:inline="javascript"> |
| th:action | 表单提交的地址 | <form action="subscribe.html" th:action="@{/subscribe}"> |
| th:remove | 删除某个属性 |
|
| th:attr | 设置标签属性,多个属性可以使用逗号分隔 | 比如 th:attr="src=@{/image/aa.jpg},title=#{logo}",此标签不太优雅,一般用的比较少。 |
Thymeleaf是什么?该如何使用。的更多相关文章
- spring boot(四):thymeleaf使用详解
在上篇文章springboot(二):web综合开发中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用.thymeleaf 是新一代的模板引擎,在spring4. ...
- Thymeleaf
1.在html顶部添加 <html xmlns:th="http://www.thymeleaf.org"> 2.url表达式 @{...} <link rel= ...
- Thymeleaf 模板的使用
Thymeleaf是现代化服务器端的Java模板引擎,不同与JSP和FreeMarker,Thymeleaf的语法更加接近HTML,并且也有不错的扩展性.详细资料可以浏览官网.本文主要介绍Thymel ...
- vert.x学习(三),Web开发之Thymeleaf模板的使用
在vert.x中使用Thymeleaf模板,需要引入vertx-web-templ-thymeleaf依赖.pom.xml文件如下 <?xml version="1.0" e ...
- 页面上使用 Thymeleaf 的内联js不当造成了 java.lang.StackOverflowError: null 问题
由于在页面上内联js使用不当,从而在从 Controller 跳转到页面时发生了以下错误: java.lang.StackOverflowError: null at org.thymeleaf.ut ...
- Thymeleaf 与 Javascript
在 javascript 代码中使用 Thymeleaf 模板引擎: <script th:inline="javascript"> $("#content& ...
- Thymeleaf+SpringMVC,如何从模板中获取数据
Thymeleaf+SpringMVC,如何从模板中获取数据 在一个典型的SpringMVC应用中,带@Controller注解的类负责准备数据模型Map的数据和选择一个视图进行渲染.这个模型Map对 ...
- Thymeleaf+Spring整合
前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thym ...
- thymeleaf常用标签
1. th:checked ,th:selected标签<input type="radio" value="M" name="gender&q ...
- thymeleaf的常见用法
1,th:属性名="",就可以直接修改控件的属性,比如 <input th:type="button" th:name="xinxin" ...
随机推荐
- 聊聊FLINK-25631贡献
从入行做数据库开发,到2018年过渡到大数据开发,可以说我已经与sql朝夕相处了七八年了,经常惊讶于简单的语法就能产生复杂的操作,而且还能根据索引等统计信息自动优化,不禁很想实现自己的sql语法,却不 ...
- 读 Angular 代码风格指南
读 Angular 代码风格指南 本文写于 2021 年 1 月 17 日 原文地址:Angular 文档 该文章拥有完整的代码风格指南--大到如何编排文件夹,小到如何进行变量命名都涉及.但是与 ng ...
- git rename branch
git 不能直接重命名远程分支,如果需要重命名则执行以下步骤操作: 重命名本地分支 删除远程分支 推送本地分支(重命名后的)到远程 额外说明: 1. 重命名后的分支也会保留历史 commit(应该是本 ...
- TinyMCE简介
TinyMCE是一款开源.易用.UI时新的富文本编辑器. 插件丰富,自带插件基本满足要求 可扩展性强,可自定义功能 界面好看,符合现代审美 提供经典.内联.沉浸无干扰三种模式 官网:https://w ...
- MyBatis热部署
代码 import java.io.IOException; import java.lang.reflect.Field; import java.util.HashMap; import java ...
- Dockerfile指令与Docker-compose容器编排-搭建docker私有仓库
目录 一:部署应用映射外部目录(持久化) 总结 二:迁移与备份(容器保存为镜像) 1.django执行gitee,项目提交到远端 2.其他操作 3.操作步骤 4.容器保存为镜像 5.把镜像打包成压缩包 ...
- L2M-GAN: Learning to Manipulate Latent Space Semantics for Facial Attribute Editing阅读笔记
L2M-GAN: Learning to Manipulate Latent Space Semantics for Facial Attribute Editing 2021 CVPR L2M-GA ...
- git指令使用
仓库为空,本地创建git项目之后提交到仓库中1.创建项目文件夹(本地git仓库)2.在项目文件夹中右键:选择Git Bash3.初始化项目:git init -- 会出现一个.git的隐藏文件夹4.将 ...
- 官方出品,比 mydumper 更快的逻辑备份工具
mysqldump 和 mydumper 是我们常用的两个逻辑备份工具. 无论是 mysqldump 还是 mydumper 都是将备份数据通过 INSERT 的方式写入到备份文件中. 恢复时,myl ...
- 「洛谷 P3834」「模板」可持久化线段树 题解报告
题目描述 给定n个整数构成的序列,将对于指定的闭区间查询其区间内的第k小值. 输入输出格式 输入格式 第一行包含两个正整数n,m,分别表示序列的长度和查询的个数. 第二行包含n个整数,表示这个序列各项 ...