当前位置:网站首页>thymeleaf迭代map集合
thymeleaf迭代map集合
2022-07-31 23:20:00 【听歌的代码】
<tr th:each="item:${session.p1}">
<!-- 查找数据 获取当前点击的对应的id-->
<!--item.getKey() 获取当前map的键-->
<!-- item.value.id 获取map集合变量id的值-->
<td name="price" th:text="${item.getKey()}"></td>
<td name="price" th:text="${item.value.id}"></td>
<td name="price" th:text="${item.value.st1}"></td>
<td name="price" th:text="${item.value.st2}"></td>
</tr>
@WebServlet("/index")
public class Ceshi extends ViewBaseServlet {
static Map<String,Pring> p1=new HashMap();
static {
p1.put("1",new Pring(1, "香蕉","20"));
p1.put("2",new Pring(2, "苹果","12"));
p1.put("3",new Pring(3, "西瓜","30"));
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession();
session.setAttribute("p1", p1);
super.processTemplate("index",req,resp);
}
}
通过
th:each="item:${session.p1}"遍历map集合item.value.id 获取map集合变量id的值
item.getKey() 获取当前map的键
使用这个对数据进行保存
HttpSession session = req.getSession();
session.setAttribute("p1", p1);也可以不用静态
边栏推荐
- [QNX Hypervisor 2.2用户手册]9.16 system
- Weekly Summary
- IDA PRO中汇编结构体识别
- [QNX Hypervisor 2.2用户手册]9.14 set
- 22年8月推广大使额外奖励规则
- 【FPGA教程案例43】图像案例3——通过verilog实现图像sobel边缘提取,通过MATLAB进行辅助验证
- In Golang go-redis cluster mode, new connections are constantly created, and the problem of decreased efficiency is solved
- 了解下C# 匿名方法
- How to import a Golang external package and use it?
- ICML2022 | 深入研究置换敏感的图神经网络
猜你喜欢

Unity-LineRenderer显示一条线

Quick Start Tutorial for flyway

21. Support Vector Machine - Introduction to Kernel Functions

Shell常用脚本:Nexus批量上传本地仓库脚本

Design of Fire and Anti-theft System Based on Single Chip GSM

手写一个简单的web服务器(B/S架构)

基于simulink的Passive anti-islanding-UVP/OVP and UFP/OFP被动反孤岛模型仿真

Golang - from entry to abandonment

基于单片机GSM的防火防盗系统的设计

Bionic caterpillar robot source code
随机推荐
cobaltstrike
二叉树非递归遍历
手写一个简单的web服务器(B/S架构)
2022-07-31:给出一个有n个点,m条有向边的图, 你可以施展魔法,把有向边,变成无向边, 比如A到B的有向边,权重为7。施展魔法之后,A和B通过该边到达彼此的代价都是7。 求,允许施展一次魔法
面试题:实现死锁
Weekly Summary
一款国外开发的高质量WordPress下载站模板主题
SQL注入 Less54(限制次数的SQL注入+union注入)
Flutter教程之四年开发经验的高手给的建议
博弈论(Depu)与孙子兵法(42/100)
I don't know what to do with sync issues
Program processes and threads (concurrency and parallelism of threads) and basic creation and use of threads
Flex layout in detail
"APIO2010" Patrol Problem Solution
VOT2021 game introduction
SQL injection Less54 (limited number of SQL injection + union injection)
助力数字政府建设,中科三方构建域名安全保障体系
[QNX Hypervisor 2.2 User Manual]9.16 system
(26)Blender源码分析之顶层菜单的关于菜单
MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储