当前位置:网站首页>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);也可以不用静态
边栏推荐
- Golang - from entry to abandonment
- 登录业务实现(单点登录+微信扫码+短信服务)
- Niuke.com brush questions (1)
- The uniapp applet checks and prompts for updates
- 「APIO2010」巡逻 题解
- Collation of knowledge points in Ningbo University NBU IT project management final exam
- Write a database document management tool based on WPF repeating the wheel (1)
- HTC使用官方固件作为底包制作rom卡刷包教程
- 无状态与有状态的区别
- TestCafeSummary
猜你喜欢
随机推荐
逐步手撕轮播图3(保姆级教程)
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#
SQL注入 Less47(报错注入) 和Less49(时间盲注)
Google Earth Engine——Error: Image.clipToBoundsAndScale, argument ‘input‘: Invalid type的错误解决
[QNX Hypervisor 2.2 User Manual]9.14 set
消息队列存储消息数据的MySQL表格
编程语言是什么
UserAgent resolution
useragent online lookup
Difference Between Stateless and Stateful
JS basic exercises
PHP三元(三目)运算符
TypeScript 的组件
How to get useragent
SQL注入 Less54(限制次数的SQL注入+union注入)
一款国外开发的高质量WordPress下载站模板主题
Network security - crack WiFi through handshake packets (detailed tutorial)
景区手绘地图的绘制流程
[QNX Hypervisor 2.2 User Manual]9.16 system
Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios









