Shop currentShop = (Shop)request.getSession().getAttribute("currentShop");
来源:8-10 商品列表展示之后端开发
weixin_慕村4009544
2019-07-04
老师,这个currentShop值为空,我回想了整个流程,实在是没想出来,老师在哪一步shopId的值设置成currentShop并丢进了session里面,希望老师指点一下
写回答
2回答
-
同学好,在拥有登录系统之后,就像下面的代码这样
private Map<String, Object> getShopManagementInfo(HttpServletRequest request) { Map<String, Object> modelMap = new HashMap<String, Object>(); long shopId = HttpServletRequestUtil.getLong(request, "shopId"); if (shopId <= 0) { Object currentShopObj = request.getSession().getAttribute("currentShop"); if (currentShopObj == null) { modelMap.put("redirect", true); modelMap.put("url", "/o2o/shopadmin/shoplist"); } else { Shop currentShop = (Shop) currentShopObj; modelMap.put("redirect", false); modelMap.put("shopId", currentShop.getShopId()); } } else { Shop currentShop = new Shop(); currentShop.setShopId(shopId); request.getSession().setAttribute("currentShop", currentShop); modelMap.put("redirect", false); } return modelMap; }
去赋值,视频会讲的,现阶段是硬编码,即指定一个固定的店铺,赋值到currentShop这个session的key里
012019-07-05 -
翔仔
2019-07-04
同学好,可以站在业务角度理解,我们这里有店家的店铺列表,然后session里面保存的是当前店铺,肯定是当他选择进入某个店铺的时候,给他从session里设置上。 然后一开始我们没有店铺列表的时候,是硬编码进去的,后面就在店铺列表点击进入某个店铺的时候设置
012019-07-04
相似问题