当前位置:网站首页>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);也可以不用静态
边栏推荐
- 一文带你了解 Grafana 最新开源项目 Mimir 的前世今生
- 「SDOI2016」征途 题解
- UOS统信系统 - WindTerm使用
- 网易云信圈组上线实时互动频道,「破冰」弱关系社交
- "SDOI2016" Journey Problem Solution
- @JsonFormat(pattern="yyyy-MM-dd") time difference problem
- Drawing process of hand-drawn map of scenic spots
- Binary tree non-recursive traversal
- SQL注入 Less42(POST型堆叠注入)
- server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none failed
猜你喜欢

(26) About menu of the top menu of Blender source code analysis

What is customer profile management?

Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)

高等代数_证明_任何矩阵都相似于一个上三角矩阵

一文带你了解 Grafana 最新开源项目 Mimir 的前世今生

消息队列消息存储设计(架构实战营 模块八作业)

2022-07-31:给出一个有n个点,m条有向边的图, 你可以施展魔法,把有向边,变成无向边, 比如A到B的有向边,权重为7。施展魔法之后,A和B通过该边到达彼此的代价都是7。 求,允许施展一次魔法

iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools

The difference between adding or not adding the ref keyword when a variable of reference type is used as a parameter in a method call in C#

Write a database document management tool based on WPF repeating the wheel (1)
随机推荐
Shell常用脚本:Nexus批量上传本地仓库脚本
【Acwing】第62场周赛 题解
内核对设备树的处理
How to identify fake reptiles?
Components of TypeScript
编程语言是什么
2022年CSP-J1 CSP-S1 第1轮初赛 报名指南
编译型语言和解释型语言的区别
2022-07-31:给出一个有n个点,m条有向边的图, 你可以施展魔法,把有向边,变成无向边, 比如A到B的有向边,权重为7。施展魔法之后,A和B通过该边到达彼此的代价都是7。 求,允许施展一次魔法
@JsonFormat(pattern="yyyy-MM-dd") time difference problem
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
Bionic caterpillar robot source code
浏览器下载快捷方式到桌面(PWA)
【FPGA教程案例43】图像案例3——通过verilog实现图像sobel边缘提取,通过MATLAB进行辅助验证
了解下C# 匿名方法
Design of Fire and Anti-theft System Based on Single Chip GSM
信息学奥赛一本通 1941:【07NOIP普及组】Hanoi双塔问题 | 洛谷 P1096 [NOIP2007 普及组] Hanoi 双塔问题
LevelSequence source code analysis
TypeScript 的组件
Learn about C# anonymous methods