当前位置:网站首页>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);也可以不用静态
边栏推荐
- SQL injection Less42 (POST type stack injection)
- SQL injection Less47 (error injection) and Less49 (time blind injection)
- Recognize anomalies (you will understand after reading this)
- The uniapp applet checks and prompts for updates
- 【ACM】2022.7.31训练赛
- #yyds dry goods inventory# Interview must brush TOP101: the entry node of the ring in the linked list
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- 一文带你了解 Grafana 最新开源项目 Mimir 的前世今生
- 不知道该怎么办的同步问题
- SQL injection Less38 (stack injection)
猜你喜欢

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

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

How to identify fake reptiles?

Recognize anomalies (you will understand after reading this)

【云驻共创】【HCSD大咖直播】亲授大厂面试秘诀

嵌入式开发没有激情了,正常吗?

Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios

Bionic caterpillar robot source code

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

浏览器下载快捷方式到桌面(PWA)
随机推荐
什么时候可以使用 PushGateway
SQL注入 Less38(堆叠注入)
登录业务实现(单点登录+微信扫码+短信服务)
信奥学习规划 信息学竞赛之路(2022.07.31)
「APIO2010」巡逻 题解
Flutter教程之 02 Flutter 桌面程序开发入门教程运行hello world (教程含源码)
Quick Start Tutorial for flyway
Learn about C# anonymous methods
网络安全--通过握手包破解WiFi(详细教程)
SQL injection Less47 (error injection) and Less49 (time blind injection)
一文带你了解 Grafana 最新开源项目 Mimir 的前世今生
C程序设计-方法与实践(清华大学出版社)习题解析
UserAgent resolution
基于simulink的Active anti-islanding-AFD主动反孤岛模型仿真
Binary tree non-recursive traversal
JS basic exercises
2022年CSP-J1 CSP-S1 第1轮初赛 报名指南
VOT2021 game introduction
In Golang go-redis cluster mode, new connections are constantly created, and the problem of decreased efficiency is solved
Document management and tools in the development process