当前位置:网站首页>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);
也可以不用静态
边栏推荐
- Payment module implementation
- 编写方法将一个数组扁平化并且去重和递增排序
- Difference Between Stateless and Stateful
- Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
- HTC使用官方固件作为底包制作rom卡刷包教程
- Bionic caterpillar robot source code
- C程序设计-方法与实践(清华大学出版社)习题解析
- LevelSequence source code analysis
- iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
- 基于RT1052 Aworks nanopb string 类型固定长度使用方式(二十七)
猜你喜欢
Collation of knowledge points in Ningbo University NBU IT project management final exam
Shell常用脚本:Nexus批量上传本地仓库脚本
Interview assault 69: TCP reliable?Why is that?
A high-quality WordPress download site template theme developed abroad
Flink 1.13(八)CDC
一文概述:VPN的基本模型及业务类型
【ACM】2022.7.31训练赛
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
In Golang go-redis cluster mode, new connections are constantly created, and the problem of decreased efficiency is solved
(26) About menu of the top menu of Blender source code analysis
随机推荐
SQL injection Less38 (stack injection)
LeetCode 第 304 场周赛
如何撰写出一篇优质的数码类好物推荐文
Advanced Algebra _ Proof _ Any matrix is similar to an upper triangular matrix
(26) About menu of the top menu of Blender source code analysis
手写一个简单的web服务器(B/S架构)
信奥学习规划 信息学竞赛之路(2022.07.31)
Interview assault 69: TCP reliable?Why is that?
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#
一文带你了解 Grafana 最新开源项目 Mimir 的前世今生
如何导入 Golang 外部包并使用它?
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
什么时候可以使用 PushGateway
EntityFramework保存到SQLServer 小数精度丢失
hboot与recovery、boot.img、system.img
Payment module implementation
PHP三元(三目)运算符
逐步手撕轮播图3(保姆级教程)
"SDOI2016" Journey Problem Solution
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs