springboot集成Thymeleaf模板

目录

springboot集成Thymeleaf模板

一 认识Thymeleaf

springboot集成Thymeleaf模板

二 springboot集成Thymeleaf

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

三 Thymeleaf的标准表达式

springboot集成Thymeleaf模板

1 标准变量表达式

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

2 选择变量表达式

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

3 URL表达式

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
加了/,就会自动加入项目工程名,如下图
springboot集成Thymeleaf模板

四 Thymeleaf的常见属性

springboot集成Thymeleaf模板

th:action

springboot集成Thymeleaf模板

th:each 循环(比较常用的)

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
下面是案例代码list示例,数组使用方法一样
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
以下是map集合的代码示例
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

th:href (参考上面的url表达式即可)

springboot集成Thymeleaf模板

th:id

springboot集成Thymeleaf模板
后台
springboot集成Thymeleaf模板
前台
springboot集成Thymeleaf模板

th:if

springboot集成Thymeleaf模板
后台model里放了一个字符串1
springboot集成Thymeleaf模板
前台比较判断(eq和=,好像都可以,不确定!!)
springboot集成Thymeleaf模板

th:unless(与if相反,是取反操作)

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
th:switch/th:case
springboot集成Thymeleaf模板

th:src (图片路径什么的)

springboot集成Thymeleaf模板

th:value

springboot集成Thymeleaf模板
下图相当于input输入框内会有解析出来的phone。如果这里是th:text,那么phone解析后会显示到输入框后面外面,而不是输入框里面
springboot集成Thymeleaf模板

th:attr (给html某元素中某属性赋值)

springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

th:onclick

springboot集成Thymeleaf模板

th:style

springboot集成Thymeleaf模板

th:mothed(直接写method就行,感觉这个没啥用)

springboot集成Thymeleaf模板

th:name

设置表单名称
springboot集成Thymeleaf模板

th:online

先看概念
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
测试内联文本
springboot集成Thymeleaf模板
测试内联脚本
springboot集成Thymeleaf模板

Thymeleaf的字面量

springboot集成Thymeleaf模板

文本字面量

springboot集成Thymeleaf模板

数字字面量

springboot集成Thymeleaf模板

boolean字面量

springboot集成Thymeleaf模板

null字面量

springboot集成Thymeleaf模板

Thymefeaf字符串拼接

springboot集成Thymeleaf模板

Thymeleaf三元运算符

springboot集成Thymeleaf模板

Thymeleaf运算和关系判断

springboot集成Thymeleaf模板

Thymeleaf表达式基本对象

springboot集成Thymeleaf模板

#request

springboot集成Thymeleaf模板
代码演示
后端放入一个name值springboot集成Thymeleaf模板
前端取出name值
springboot集成Thymeleaf模板

#session

springboot集成Thymeleaf模板
代码演示
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

Thymaleaf表达式功能对象

先大概看一下springboot集成Thymeleaf模板
springboot集成Thymeleaf模板

*代码举例1 :格式化时间格式
springboot集成Thymeleaf模板
前端取出时间并格式化显示springboot集成Thymeleaf模板
代码示例2:字符串截取
springboot集成Thymeleaf模板
springboot集成Thymeleaf模板
真正使用时查官方文档
函数示例springboot集成Thymeleaf模板