文章目录

  • 一、渲染机制
  • 二、导入thymeleaf的名称空间
  • 四、使用thymeleaf
  • 五、语法规则
    • 1.属性及属性的优先级
    • 2.表达式

一、渲染机制

@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");public static final String DEFAULT_PREFIX = "classpath:/templates/";public static final String DEFAULT_SUFFIX = ".html";

以前的SpringMVC会给我们拼串得到jsp页面,而现在
只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染,依据来自上面的代码String DEFAULT_PREFIX = “classpath:/templates/”;
访问地址如:classpath:/templates/success.html

二、导入thymeleaf的名称空间

<html lang="en" xmlns:th="http://www.thymeleaf.org">

四、使用thymeleaf

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><h1>成功!</h1><!--th:text 将div里面的文本内容设置为 --><div th:text="${hello}">这是显示欢迎信息</div>
</body>
</html>

五、语法规则

1.属性及属性的优先级

th:text;改变当前元素里面的文本内容;
th:任意html属性;还可以替换原生属性的值

2.表达式

Simple expressions:(表达式语法)- Variable Expressions: ${...}:获取变量值;OGNL;1)、获取对象的属性、调用方法2)、使用内置的基本对象:#ctx : the context object.#vars: the context variables.#locale : the context locale.#request : (only in Web Contexts) the HttpServletRequest object.#response : (only in Web Contexts) the HttpServletResponse object.#session : (only in Web Contexts) the HttpSession object.#servletContext : (only in Web Contexts) the ServletContext object.3)、内置的一些工具对象:#execInfo : information about the template being processed.#messages : methods for obtaining externalized messages inside variables                 expressions, in the same way as they would be obtained using #{…} syntax.#uris : methods for escaping parts of URLs/URIs#conversions : methods for executing the configured conversion service (if any).#dates : methods for java.util.Date objects: formatting, component extraction, etc.#calendars : analogous to #dates , but for java.util.Calendar objects.#numbers : methods for formatting numeric objects.#strings : methods for String objects: contains, startsWith, prepending/appending, etc.#objects : methods for objects in general.#bools : methods for boolean evaluation.#arrays : methods for arrays.#lists : methods for lists.#sets : methods for sets.#maps : methods for maps.#aggregates : methods for creating aggregates on arrays or collections.#ids : methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).- Selection Variable Expressions: *{...}:选择表达式:和${}在功能上是一样;补充:配合 th:object="${session.user}:<div th:object="${session.user}"><p>Name: <span th:text="*{firstName}">Sebastian</span>.</p><p>Surname: <span th:text="*{lastName}">Pepper</span>.</p><p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p></div>- Message Expressions: #{...}:获取国际化内容- Link URL Expressions: @{...}:定义URL;@{/order/process(execId=${execId},execType='FAST')}- Fragment Expressions: ~{...}:片段引用表达式<div th:insert="~{commons :: main}">...</div>- Literals(字面量)Text literals: 'one text' , 'Another one!' ,…Number literals: 0 , 34 , 3.0 , 12.3 ,…Boolean literals: true , falseNull literal: nullLiteral tokens: one , sometext , main ,…- Text operations:(文本操作)String concatenation: +Literal substitutions: |The name is ${name}|- Arithmetic operations:(数学运算)Binary operators: + , - , * , / , %Minus sign (unary operator): -- Boolean operations:(布尔运算)Binary operators: and , orBoolean negation (unary operator): ! , not- Comparisons and equality:(比较运算)Comparators: > , < , >= , <= ( gt , lt , ge , le )Equality operators: == , != ( eq , ne )- Conditional operators:条件运算(三元运算符)If-then: (if) ? (then)If-then-else: (if) ? (then) : (else)Default: (value) ?: (defaultvalue)- Special tokens:No-Operation: _

学习内容来自尚硅谷

Spring Boot—thymeleaf语法规则以及使用相关推荐

  1. Spring Boot Thymeleaf(十一)

    一.Thymeleaf 简介 Thymeleaf 是一款用于渲染 XML/XHTML/HTML5 内容的模板引擎.它与 JSP,Velocity,FreeMaker 等模板引擎类似,也可以轻易地与 S ...

  2. Spring Boot - Thymeleaf模板简介以及集成

    文章目录 Spring Boot - Thymeleaf模板简介以及集成 1.什么是Thymeleaf? 2.标准表达式 2.1 变量表达式 2.2 选择表达式/星号表达式 2.3 URL表达式 2. ...

  3. Spring Boot整合Drools规则引擎实例

    1.DRools介绍 官网:https://www.drools.org/ 规则引擎主要完成的就是将业务规则从代码中分离出来. DRools一款由JBoss组织提供的基于Java语言开发的开源规则引擎 ...

  4. Spring Boot + Thymeleaf 创建web项目

    本篇文章将引导你创建一个简单的Spring Boot web程序示例,涉及到的组件有:嵌入的Tomcat + Thymeleaf 模板引擎,可执行的 JAR 文件包. 开发工具: 1.Spring B ...

  5. Spring boot+Thymeleaf+easyui集成:js创建组件页面报错

    开发工具:Ideal 使用场景:Demo 前提:        环境:Spring boot +Thymeleaf+easyui 引入thymeleaf模板引擎 1 <html lang=&qu ...

  6. thymeleaf的能用在什么地方_细品 Spring Boot+Thymeleaf,还有这么多好玩的细节!

    松哥原创的 Spring Boot 视频教程已经杀青,感兴趣的小伙伴戳这里-->松哥要升级 SpringBoot 视频了,看看新增了哪些内容! 虽然现在流行前后端分离,但是后端模版在一些关键地方 ...

  7. Spring boot - Thymeleaf 使用

    1,thymeleaf 简介 thymeleaf 是一个spring boot中推荐使用的比较新的java模板引擎.其使用场景可以在html.javascript.css.xml.text当中.在官方 ...

  8. 细品 Spring Boot+Thymeleaf,还有这么多好玩的细节!

    文章目录 1. Thymeleaf 简介 2. 整合 Spring Boot 2.1 基本用法 2.2 手动渲染 3. Thymeleaf 细节 3.1 标准表达式语法 3.1.1 简单表达式 3.1 ...

  9. Spring Boot Themeleaf语法

    Spring 整合HTML Spring boot可以结合 Thymeleaf 模板整合HTML,使用原生的HTML作为视图 Thymeleaf 模板是面向 Web 和独立环境的 java模板引擎,它 ...

最新文章

  1. PHP 读写数据库出现中文乱码问题
  2. 49 jQuery事件
  3. Codeforces 448E Divisors
  4. python错误-Python错误解决
  5. 人工智能AI、机器学习和深度学习之间的区别是什么?
  6. 面试官让我讲下线程的TIMED_WAITING状态,我又笑了
  7. linux中匿名用户怎么登陆_南京课工场IT培训:Linux中vsftpd服务配置(匿名,用户,虚拟用户)...
  8. MySQL笔记-Linux平台中MySQL的启动和关闭
  9. android 全局定时器,高通Android LED驱动移植-GPIO,内核定时器
  10. 中电信总工:我国将在2011底出现IP短缺
  11. 用java怎么做中国象棋的小游戏_java开发中国象棋小游戏
  12. zmud中的ansi颜色使用
  13. android 通知栏授权,Android 消息通知栏Notification使用和权限
  14. 阻止浏览器默认行为事件
  15. 小尺寸android 手机推荐,喜欢小屏安卓手机的来看看,这三款便宜又好用
  16. 【机器学习实战】利用KNN和其他分类器对手写数字进行识别
  17. Python之高阶函数(abs、map、reduce、filter、lambda匿名函数)
  18. MySql安装配置(msi版)
  19. 华为与这三所一流大学又有新互动!
  20. FFmpeg 视频处理入门教程(转)

热门文章

  1. HDOJ 5147 Sequence II 树阵
  2. C# 使用正则表达式去掉字符串中的数字,或者去掉字符串中的非数字
  3. grub安装的 三种安装方式
  4. MOSS的SPBuiltInFieldId成员的字段类型对照关系表
  5. 据说看完这21个故事的人,30岁前都成了亿万富翁。你是下一个吗
  6. Resin禁止目录访问
  7. awk和cut分割字符区别
  8. malloc原理和内存碎片
  9. OpenCV图像处理使用笔记(五)——图像边界拓展
  10. python日期格式修改年月日_Python time模块格式化中文年月日