当前位置:网站首页>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>
效果
边栏推荐
- Faire un clip vidéo auto - média deux fois, comment clip n'est pas considéré comme une infraction
- LeetCode_ 67 (binary sum)
- [buuctf.reverse] 152-154
- SAS接口有什么优势特点
- poi设置列的数据格式(有效)
- TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
- LeetCode_ 3 (longest substring without repeated characters)
- C - Divisors of the Divisors of An Integer Gym - 102040C
- Getting started with rce
- TDengine 社区问题双周精选 | 第三期
猜你喜欢
TiCDC 6.0原理之Sorter演进
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
Why do mechanical engineers I know complain about low wages?
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
Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
随机推荐
无密码身份验证如何保障用户隐私安全?
软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】
强联通分量
C - Divisors of the Divisors of An Integer Gym - 102040C
R language uses boxplot function in native package (basic import package, graphics) to visualize box plot
[buuctf.reverse] 152-154
Current situation, trend and view of neural network Internet of things in the future
VC开发非MFC程序内存泄漏跟踪代码
R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
POI set the data format of the column (valid)
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
03_Solr之dataimport
清大科越冲刺科创板:年营收2亿 拟募资7.5亿
最简单不用证书也可以多开功能的方式
国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
Webrtc learning (II)
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
如何深入理解“有限状态机”的设计思想?