实战SSM_O2O商铺_23【商铺列表】Controller层开发
生活随笔
收集整理的這篇文章主要介紹了
实战SSM_O2O商铺_23【商铺列表】Controller层开发
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 概述
- ShopController
- 單元測試
- Github地址
概述
按照頁面原型 控制層有2個功能要開發
- 獲取商鋪列表
- 然后根據連接對某個單一的商鋪進行操作(管理頁面主要是對session部分的操作)
ShopController
/*** * * @Title: getShopList* * @Description: 從session中獲取當前person擁有的商鋪列表* * @param request* @return* * @return: Map<String,Object>*/@RequestMapping(value = "/getshoplist", method = RequestMethod.GET)@ResponseBodypublic Map<String, Object> getShopList(HttpServletRequest request) {Map<String, Object> modelMap = new HashMap<String, Object>();// 現在還沒有做登錄模塊,因此session中并沒有用戶的信息,先模擬一下登錄 要改造TODOPersonInfo personInfo = new PersonInfo();personInfo.setUserId(1L);personInfo.setName("小工匠");request.getSession().setAttribute("user", personInfo);// 從session中獲取user信息personInfo = (PersonInfo) request.getSession().getAttribute("user");try {Shop shopCondition = new Shop();shopCondition.setOwner(personInfo);ShopExecution se = shopService.getShopList(shopCondition, 1, 99);modelMap.put("success", true);modelMap.put("shopList", se.getShopList());modelMap.put("user", personInfo);} catch (ShopOperationException e) {e.printStackTrace();modelMap.put("success", false);modelMap.put("errMsg", e.getMessage());}return modelMap;}/*** * * @Title: shopManagement* * @Description: 從商鋪列表頁面中,點擊“進入”按鈕進入* 某個商鋪的管理頁面的時候,對session中的數據的校驗從而進行頁面的跳轉,是否跳轉到店鋪列表頁面或者可以直接操作該頁面* * 訪問形式如下* http://ip:port/o2o/shopadmin/shopmanagement?shopId=xxx* * @return* * @return: Map<String,Object>*/@RequestMapping(value = "/getshopmanageInfo", method = RequestMethod.GET)@ResponseBodypublic Map<String, Object> getShopManageInfo(HttpServletRequest request) {Map<String, Object> modelMap = new HashMap<String, Object>();// 獲取shopIdlong shopId = HttPServletRequestUtil.getLong(request, "shopId");// 如果shopId不合法if (shopId < 0) {// 嘗試從當前session中獲取Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");if (currentShop == null) {// 如果當前session中也沒有shop信息,告訴view層 重定向modelMap.put("redirect", true);modelMap.put("url", "/o2o/shopadmin/shoplist");}else{// 告訴view層 進入該頁面modelMap.put("redirect", false);modelMap.put("shopId", currentShop.getShopId());}} else { // shopId合法的話Shop shop = new Shop();shop.setShopId(shopId);// 將currentShop放到session中request.getSession().setAttribute("currentShop", shop);modelMap.put("redirect", false);}return modelMap;}單元測試
單元測試我們開發完頁面后一并測試。
Github地址
代碼地址: https://github.com/yangshangwei/o2o
總結
以上是生活随笔為你收集整理的实战SSM_O2O商铺_23【商铺列表】Controller层开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实战SSM_O2O商铺_22【商铺列表】
- 下一篇: 实战SSM_O2O商铺_24【商铺列表】