当前位置:网站首页>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>
效果
边栏推荐
- OSI and tcp/ip protocol cluster
- TiFlash 面向编译器的自动向量化加速
- R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
- Sorter evolution of ticdc 6.0 principle
- 软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
- tidb-dm报警DM_sync_process_exists_with_error排查
- 01 、Solr7.3.1 在Win10平台下使用jetty的部署及配置
- 判断变量是否为数组
- Assembly language
- LeetCode_ 69 (square root of x)
猜你喜欢

Brief introduction to revolutionary neural networks

openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)

明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿

清大科越冲刺科创板:年营收2亿 拟募资7.5亿

无密码身份验证如何保障用户隐私安全?

如何深入理解“有限状态机”的设计思想?

世界环境日 | 周大福用心服务推动减碳环保

What is the future development trend of neural network Internet of things

循环不变式

Introduction, installation, introduction and detailed introduction to postman!
随机推荐
展现强大。这样手机就不会难前进
做自媒体视频二次剪辑,怎样剪辑不算侵权
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
Google eventbus usage details
How to introduce devsecops into enterprises?
Brief introduction to revolutionary neural networks
Implementation process of WSDL and soap calls under PHP5
Tiflash compiler oriented automatic vectorization acceleration
LeetCode_3(无重复字符的最长子串)
R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
Discussion on memset assignment
VC开发非MFC程序内存泄漏跟踪代码
How to deeply understand the design idea of "finite state machine"?
R language ggplot2 visual bar graph: visualize the bar graph through the two-color gradient color theme, and add label text for each bar (geom_text function)
Laravel - view (new and output views)
让秒杀狂欢更从容:大促背后的数据库(下篇)
Recommendation number | what are interesting people looking at?
TiCDC 6.0原理之Sorter演进
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析