当前位置:网站首页>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>
效果
边栏推荐
- 分享 12 个最常用的正则表达式,能解决你大部分问题
- IP packet header analysis and static routing
- R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to each vari
- TDengine 社区问题双周精选 | 第三期
- 金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
- Laravel - view (new and output views)
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义X轴的轴标签文本(customize X axis labels)
- Webrtc learning (II)
- How to call the function mode of one hand and one machine
- Getting started with rce
猜你喜欢
How to introduce devsecops into enterprises?
How to deeply understand the design idea of "finite state machine"?
Sorter evolution of ticdc 6.0 principle
神经网络物联网未来发展趋势怎么样
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares
upload (1-6)
ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
Tiflash compiler oriented automatic vectorization acceleration
Why do mechanical engineers I know complain about low wages?
随机推荐
Current situation, trend and view of neural network Internet of things in the future
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
Tiflash compiler oriented automatic vectorization acceleration
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
Lepton 无损压缩原理及性能分析
Sqllab 1-6 exercise
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and use the labs parameter to customize the X axis label text (customize X axis labels)
循环不变式
矩阵链乘 - 动态规划实例
Discussion on memset assignment
微服务项目部署后,无法访问静态资源,无法访问到上传到upload中的文件,解决办法
Sorter evolution of ticdc 6.0 principle
Simple process of penetration test
After the microservice project is deployed, static resources and files uploaded to upload cannot be accessed. Solution
How to deeply understand the design idea of "finite state machine"?
2022 driller (drilling) examination question bank and simulation examination
神经网络物联网未来发展趋势怎么样
R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
Webrtc learning (II)