SpringBoot学习笔记【part12】Web开发——Thymeleaf模板引擎

SpringBoot学习笔记【part12】Web开发——Thymeleaf模板引擎,第1张

SpringBoot学习笔记【part12】Web开发——Thymeleaf模板引擎 SpringBoot 学习笔记 Part12 1. thymeleaf简介

SpringBoot默认不支持 JSP,需要引入第三方模板引擎技术实现页面渲染。

Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, Javascript, CSS and even plain text.

即 thymeleaf 是现代化、服务端的Java模板引擎。


2. 基本语法

表达式

表达式名语法作用变量取值${…}获取请求域、session域、对象等值选择变量*{…}获取上下文对象值消息#{…}获取国际化等值链接@{…}生成链接片段表达式~{…}jsp:include 作用,引入公共页面片段行内表达式[[…]]HTML 文本中嵌套表达式

字面量

文本值:‘one text’ , ‘another one’

数字:0 , 34 , 3.0 , 12.3

布尔值:true , false

空值:null

变量:one,two

文本 *** 作

字符串拼接: +

变量替换: |The name is ${name}|

数字运算

运算符: + , - , * , / , %

布尔运算

运算符: and , or

一元运算: ! , not

比较运算

比较: > , < , >= , <= ( gt , lt , ge , le )

等式: == , != ( eq , ne )

条件运算

If-then: (if) ?(then)

If-then-else: (if) ? (then) :(else)

Default: (value) ? :(defaultvalue)

特殊 *** 作

无 *** 作: _


3. 标签th:attr

th:attr 用来设置属性值。

设置单个值:

 

设置多个值:



以上两个的代替写法:


所有h5兼容的标签写法可参考官方文档:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#setting-value-to-specific-attributes


4. 迭代

foreach:

迭代普通类型:


        Onions
        2.41
        yes

迭代对象:


  Onions
  2.41
  yes


5. 条件运算

if:

view

switch:

  

User is an administrator

User is a manager

User is some other thing

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5721624.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-18

发表评论

登录后才能评论

评论列表(0条)

保存