如何获得Map<String,Map>里面的值,Map里面保存了一个Map,如何获得值

如何获得Map<String,Map>里面的值,Map里面保存了一个Map,如何获得值

这个其实也很简单。

请看以下java代码片段

Map<String, Object> shopdetails = new HashMap<String, Object>();
		ShopInformation shopInformation = siiter.getShopInformation(shopid); //获得指定商品
		shopdetails.put("shopimg", shopInformation.getShopimg());
		shopdetails.put("shopname", shopInformation.getShopname());
		shopdetails.put("shopid", shopInformation.getShopid());
		shopdetails.put("subshopStock", shopInformation.getSubshopStock());
		shopdetails.put("shopdes", shopInformation.getShopdes());
		shopdetails.put("shopprice", shopInformation.getShopprice());
上面是一个Map

下面的代码是,重新创建另一个Map,将上面的Map保存进去

Map<String,Object> map = new HashMap<String,Object>();
map.put("shopdetails", shopdetails);
那么,在前端jsp页面我们应该如何获得这个Map的内容呢

请看如下代码

//获得map
<c:set var="sdetails" value="${shopdetails}" />
此时获得到的是Map,这个Map里保存的就是我们的数据

您可以这样获得数据

${sdetails.shopname}
当然您还可以遍历Map,您可以查看以下连接

JSTL如何遍历List中的Map


爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情Blog Img