thymeleaf的简单记录

thymeleaf的简单记录


1:springboot项目的thymeleaf资源放置于resource/templates下

 application.properties中需要增加下面的配置

 

1
2
3
4
5
#html的thymeleaf静态资源的导入以及配置
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.enabled=true

2:定义html的thymeleaf模板需要引入thymeleaf的命名空间

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

3:相关语法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1:单变量传递th:text =${变量}    使用该标签接受变量取值
 
1举例:
 
后台:
model.addAttribute("msg",要传递的内容);
 
前台:
 
<div th:text="${msg}"></div>2:循环体传递
th:each= "单体名:${循环体}" th:text="${单体名}"
 
2:举例:
 
后台:
model.addAttribute("users", Arrays.asList("mike","jetty","mary"));
前台:
<h3 th:each="user:${users}" th:text="${user}"></h3>

  

 

 

 

posted on   晨哥  阅读(28)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示