当前位置:网站首页>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>
效果
边栏推荐
- Assembly language
- 2022 construction welder (special type of construction work) special operation certificate examination question bank and online simulation examination
- R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
- WebRTC的学习(二)
- 广发期货排名多少?网上办理广发期货开户安全可靠吗?
- 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
- R语言使用ggplot2包的geom_histogram函数可视化直方图(histogram plot)
- 判断变量是否为数组
- Laravel - model (new model and use model)
- 做自媒体视频二次剪辑,怎样剪辑不算侵权
猜你喜欢

Postman简介、安装、入门使用方法详细攻略!

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

Comparison of several distributed databases

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

Sorter evolution of ticdc 6.0 principle

基于 TiDB 场景式技术架构过程 - 理论篇

ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)

ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)

金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功

神经网络物联网未来现状和趋势及看法
随机推荐
循环不变式
无密码身份验证如何保障用户隐私安全?
Fault analysis | analysis of an example of MySQL running out of host memory
Comparison of several distributed databases
MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
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)
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功
Lepton 无损压缩原理及性能分析
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
LeetCode_ 67 (binary sum)
Webrtc learning (II)
Redis如何实现多可用区?
判断变量是否为数组
Linux下mysql数据库安装教程
poi设置列的数据格式(有效)
非技术部门,如何参与 DevOps?
03_Solr之dataimport
01 、Solr7.3.1 在Win10平台下使用jetty的部署及配置