Thymeleaf页面静态化

Thymeleaf
1.1 页面静态化
程序被访问之前, 预先生成静态页面html , 用户在进行访问时, 只需要访问预先生成的静态页面 ,而不需要发送ajax请求加载数据;
1.2 Thymeleaf介绍
Thymeleaf是一个模板引擎 , 可以用来生成任何文本文件(html, css, js , java ,txt);
Thymeleaf可以和SpringMVC , SpringBoot无缝集成, 可以完全的替换 JSP 来完成视图的展示及渲染 , 可以替换其他的模板引擎 Freemarker , Velocity ;
作用 :
1). 代替JSP完成页面展示及渲染 ;
2). 代替其他的模板引擎实现页面静态化 ;
在这里插入图片描述

1.3 SpringBoot-Thymeleaf
1). pom.xml

org.springframework.boot
spring-boot-starter-parent
2.1.4.RELEASE


org.springframework.boot spring-boot-starter-web ​ org.springframework.boot spring-boot-starter-thymeleaf

2). 引导类
3). application.yml
spring:
thymeleaf:
cache: false

4). 模板文件(页面)
demo.html

Title

5). controller
@Controller
@RequestMapping("/demo")
public class DemoController {
@GetMapping("/test")
public String test(Model model){
model.addAttribute(“hello”,“hello world”);
return “demo”;//代表的是视图的名称 , 会找到templates的目录下demo.html
}
}

1.4 基本语法
1).输出文本

2). 表单提交

确定

URL 声明的语法 : @{url}
3). 循环迭代 th:each
A. 遍历List

indexidnameaddress

user : 代表遍历出来的元素 ;
userStat : 状态变量, 通过状态变量可以获取循环的下表 , 元素个数 , 当前元素 ; (可选)

B. 遍历Map

key:
value:

C. 遍历数组

4). 日期输出

5). 判断 th:if

终于成年了

th:if
th:unless
6). 模块声明 th:fragment

关于我们

7). 页面包含 th:include=""

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值