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" ...
随机推荐
- Bert不完全手册5. 推理提速?训练提速!内存压缩!Albert
Albert是A Lite Bert的缩写,确实Albert通过词向量矩阵分解,以及transformer block的参数共享,大大降低了Bert的参数量级.在我读Albert论文之前,因为Albe ...
- 多线程07:async、future、packaged_task、promise
async.future.packaged_task.promise 本节内容需要包含头文件:#include <future> 一.std::async. std::future 创建后 ...
- ELK 1.4 logstash各种插件
kibana各种插件: 1.过虑插件 kv (1)KV插件:接收一个键值数据,按照指定分隔符解析为Logstash 事件中的数据结构,放到事件顶层. 常用字段: • field_split ...
- 小米 pro 笔记本双硬盘设置引导盘
功能键 F2 进入 BIOS F12 进入 Boot 选项 步骤 小米 Pro 默认是开启了 UEFI,如果 Boot 选项没有显示出期望的系统盘,那么就是这个系统盘没有 UEFI 分区,按照这个文档 ...
- 运维:DevSecOps
什么是DevSecOps DevSecOps 是一场关于 DevOps 概念实践或艺术形式的变革.DevOps之父Patrick Debios 强调:"DevOps2.0时代应首先解决人的问 ...
- MySql笔记Ⅰ
MySql part 1: 数据库概念 数据库:(DataBase, 简称DB):数据库中的数据按一定的数据模型组织.描述和储存,具有较小的冗余度.较高的数据独立性和易扩展性,并可为各种 用户共享 数 ...
- 关于TornadoFx和Android的全局配置工具类封装实现及思路解析
原文地址: 关于TornadoFx和Android的全局配置工具类封装实现及思路解析 - Stars-One的杂货小窝 目前个人开发软件存在设置页面,可以让用户自定义些设置,但我发现,存储数据的代码逻 ...
- 在linux上开启酸酸乳,未完待续
在服务器调试深度学习环境的时候总需要下载conda的包,一直以来都觉得是因为国内访问慢,于是想在服务器上开 ,或者ssr.由于过去用ssr多一些,于是想了解ssr on linux. 1.首先win1 ...
- GDKOI 2021 Day1 PJ 爆炸记
早上睡到 7:10 分才想起今天有 GDKOI ,赶紧去买了一个面包赶去机房 发现隔壁的大奆都过来了.比赛时由于昨晚一直没睡好,打了两个小时的哈欠 T1 :暴力模拟 根据 \(r\) 和 \(c\) ...
- WinForms拖控件拖到天荒地老
更新记录: 2022年4月15日:本文迁移自Panda666原博客,原发布时间:2021年4月18日. 2022年4月15日:更新自动生成Web CURD工具. 说明 Winforms的控件拖起来是真 ...