当前位置:网站首页>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);
也可以不用静态
边栏推荐
- Judging decimal points and rounding of decimal operations in Golang
- UserAgent resolution
- 面试突击69:TCP 可靠吗?为什么?
- 如何减少软件设计和实现之间鸿沟
- 2022年CSP-J1 CSP-S1 第1轮初赛 报名指南
- Unity - by casting and cloning method dynamic control under various UGUI create and display
- 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#
- HTC使用官方固件作为底包制作rom卡刷包教程
- Shell常用脚本:Nexus批量上传本地仓库脚本
- iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
猜你喜欢
Unity - by casting and cloning method dynamic control under various UGUI create and display
Mysql environment installation under Linux (centos)
Dry goods | 10 tips for MySQL add, delete, change query performance optimization
硬件设备计算存储及数据交互杂谈
[NLP] What is the memory of the model!
Shell common script: Nexus batch upload local warehouse script
ICML2022 | 深入研究置换敏感的图神经网络
二叉树非递归遍历
Design of Fire and Anti-theft System Based on Single Chip GSM
Audio alignment using cross-correlation
随机推荐
Judging decimal points and rounding of decimal operations in Golang
逐步手撕轮播图3(保姆级教程)
SQL27 View user details of different age groups
Flutter教程之四年开发经验的高手给的建议
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#
TypeScript 的组件
Drawing process of hand-drawn map of scenic spots
Weekly Summary
Shell common scripts: Nexus batch upload local warehouse enhanced version script (strongly recommended)
嵌入式开发没有激情了,正常吗?
Network security - crack WiFi through handshake packets (detailed tutorial)
[QNX Hypervisor 2.2 User Manual]9.14 set
Design of Fire and Anti-theft System Based on Single Chip GSM
不知道该怎么办的同步问题
【ACM】2022.7.31训练赛
SQL注入 Less47(报错注入) 和Less49(时间盲注)
ICML2022 | 深入研究置换敏感的图神经网络
基于单片机GSM的防火防盗系统的设计
iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
支付模块实现