当前位置:网站首页>Thymeleaf th:with局部变量的使用
Thymeleaf th:with局部变量的使用
2022-07-05 14:10:00 【fengyehongWorld】
后台数据准备
ZTestEntity zTestEntity = new ZTestEntity();
List<Person> personList = Arrays.asList(
new Person("1", "贾飞天", "20")
, new Person("2", "张三", "21")
);
zTestEntity.setPersonList(personList);
return zTestEntity;
// ---------------------------------------------------
@GetMapping("/init2")
public ModelAndView init2() {
ModelAndView modelAndView = new ModelAndView();
ZTestEntity entity = service.init();
modelAndView.addObject("entity", entity);
modelAndView.setViewName("test2");
return modelAndView;
}
前台test2.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>test2页面的标题</title>
</head>
<body>
<div id="container" th:object="${entity}">
<!-- 使用th:with将person0Id和personInfo被处理为一个局部变量, 作用于div之内的任何子元素上 -->
<div th:with=" person0Id=*{personList[0].personId} ,personInfo=*{personList[1]} ">
<!-- 内部的div使用外部div定义的局部变量 -->
<div th:text="${person0Id}"></div>
<div>[[${personInfo.personId}]]</div>
<hr>
<!-- Thymeleaf标签的又一种写法,利用了html5的 data- 属性 th:标签名 全部可以使用 data-th-标签名的这种形式来替代 -->
<div data-th-text="${personInfo.personName}"></div>
</div>
</div>
</body>
</html>
效果
边栏推荐
- Show strength. In this way, the mobile phone will not be difficult to move forward
- Faire un clip vidéo auto - média deux fois, comment clip n'est pas considéré comme une infraction
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义X轴的轴标签文本(customize X axis labels)
- 金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
- Redis如何实现多可用区?
- 用“新”字来吸引好奇的人群
- 魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
- 金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功
- 2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
- LeetCode_ 3 (longest substring without repeated characters)
猜你喜欢
无密码身份验证如何保障用户隐私安全?
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
TiCDC 6.0原理之Sorter演进
国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
Scenario based technology architecture process based on tidb - Theory
OSI and tcp/ip protocol cluster
-Web direction attack and defense world
TiFlash 面向编译器的自动向量化加速
ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
区间 - 左闭右开
随机推荐
让秒杀狂欢更从容:大促背后的数据库(下篇)
IP packet header analysis and static routing
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
03_Solr之dataimport
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
The simplest way to open more functions without certificates
魅族新任董事长沈子瑜:创始人黄章先生将作为魅族科技产品战略顾问
3W principle [easy to understand]
Why do mechanical engineers I know complain about low wages?
Postman简介、安装、入门使用方法详细攻略!
做自媒体视频二次剪辑,怎样剪辑不算侵权
Scenario based technology architecture process based on tidb - Theory
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
基于 TiDB 场景式技术架构过程 - 理论篇
Enjoy what you want. Zhichuang future
How to introduce devsecops into enterprises?
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
Sqllab 1-6 exercise