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" ...
随机推荐
- 好客租房14-在jsx中使用javascript表达式的注意点
注意点 单大括号中可以使用任意的表达式 jsx自身也是js表达式 注意:js中的对是一个例外 写在style样式中 //导入react import React from "reac ...
- python并发编程之线程/协程
python并发编程之线程/协程 part 4: 异步阻塞例子与生产者消费者模型 同步阻塞 调用函数必须等待结果\cpu没工作input sleep recv accept connect get 同 ...
- ApeForms | WinForm窗体UI美化库(Metro扁平风格)演示与安装
ApeForms系列① 快速上手 @ 目录 ApeForms系列① 快速上手 前言 演示视频 快速上手 安装及使用 Demo下载 联系开发者 加入我们 建议与咨询 前言 ApeForms是一套基于Wi ...
- 我的第一个开源作品Kiwis2 Mock Server
我的第一个开源作品Kiwis2 Mock Server,目前公测中,欢迎大家提供宝贵意见. 代码:https://github.com/kiwis2/mockserver 主页:https://kiw ...
- 计算机网络 - OSI 7层网络模型各层对应的功能
应用层 - 负责给应用程序提供统一的接口 表示层 - 负责把数据的解压缩和编码 会话层 - 负责会话的管理(建立和终止) 传输层 - 负责端到端的数据传输 网络层 - 负责数据的路由.转发.分片 数据 ...
- 前端2CSS
内容概要 form表单 网络请求方式 CSS简介 CSS查找标签之基本选择器(重要) CSS查找标签之组合选择器(重要) 属性选择器 分组与嵌套 伪类选择器 内容详情 form表单 "&qu ...
- 拥抱 OpenAPI 3:springdoc-openapi 食用指南
概述 使用 springdoc-openapi 可以快速为 springboot 项目生成规范的 API 文档,具体使用步骤如下: 依赖配置 在 pom.xml 加入内容,即可开始使用: <de ...
- JVM学习笔记-从底层了解程序运行(一)
1:JVM基础知识 什么是JVM 1. java虚拟机,跨语言的平台,实现java跨平台 2. 可以实现多种语言跨平台,只要该语言可以编译成.class文件 3. 解释执行.class文件 java是 ...
- 使用http://start.spring.io/构建maven微服务项目的几个坑及eclipse构建spring boot微服务项目
一,使用http://start.spring.io/构建maven微服务项目 本来嘛,直接构建的项目导入时没有任何问题的导入就可以运行,可是最近构建好项目,然后导入,种种报错 1.导入之后POM报错 ...
- 【机器学习】数据准备--python爬虫
前言 我们在学习机器学习相关内容时,一般是不需要我们自己去爬取数据的,因为很多的算法学习很友好的帮助我们打包好了相关数据,但是这并不代表我们不需要进行学习和了解相关知识.在这里我们了解三种数据的爬取: ...