获取商铺列表
1 @RequestMapping(value = "/getshoplist",method = RequestMethod.GET) 2 @ResponseBody 3 private Map<String , Object> getShopList(HttpServletRequest request){ 4 Map<String, Object> modelMap = new HashMap<String,Object>(); 5 PersonInfo user = new PersonInfo(); 6 //因为如果没有用户登录 所以先设置个默认值 模拟用户登录 7 user.setUserId(1L); 8 user.setName("test"); 9 request.getSession().setAttribute("user", user); 10 11 user = (PersonInfo) request.getSession().getAttribute("user"); 12 try { 13 Shop shopCondition = new Shop(); 14 shopCondition.setOwner(user);//将Session中的user获取到 15 ShopExecution se = shopService.getShopList(shopCondition, 0, 100);//一个人最多创建一百条 16 modelMap.put("shopList", se.getShopList()); 17 modelMap.put("user", user); 18 modelMap.put("success", true); 19 }catch (Exception e) { 20 modelMap.put("success", false); 21 modelMap.put("errMsg", e.getMessage()); 22 } 23 return modelMap; 24 25 }
对用户Session的管理
1 /** 2 *管理session相关的 3 * @param request 4 * @return 5 */ 6 @RequestMapping(value="/getshopmanagementinfo", method=RequestMethod.GET) 7 @ResponseBody 8 public Map<String, Object> getShopManagementInfo(HttpServletRequest request){ 9 Map<String, Object> modelMap = new HashMap<>(); 10 long shopId = (long) request.getSession().getAttribute("shopId"); 11 //如果shopId不存在 12 if(shopId <= 0){ 13 //判断当前有没有登录 14 Object currentShopObj = request.getSession().getAttribute("currentShop"); 15 //如果当前既没有shopId传入,也没有店铺登录的话,就重定向到店铺列表页面 16 if(currentShopObj == null){ 17 modelMap.put( "redirect", true ); 18 modelMap.put( "url", "/shop/shoplist" ); 19 }else{ 20 //如果当前有店铺登录的话 21 Shop currentShop = (Shop)currentShopObj; 22 modelMap.put( "redirect", false ); 23 modelMap.put( "shopId", currentShop.getShopId()); 24 } 25 }else{ 26 //如果当前有shopId 27 Shop currentShop = new Shop(); 28 currentShop.setShopId(shopId); 29 request.getSession().setAttribute("currentShop", currentShop); 30 modelMap.put( "redirect", false ); 31 } 32 return modelMap; 33 }