日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

实战SSM_O2O商铺_23【商铺列表】Controller层开发

發(fā)布時間:2025/3/21 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实战SSM_O2O商铺_23【商铺列表】Controller层开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 概述
  • ShopController
  • 單元測試
  • Github地址

概述

按照頁面原型 控制層有2個功能要開發(fā)

  • 獲取商鋪列表
  • 然后根據連接對某個單一的商鋪進行操作(管理頁面主要是對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;}

單元測試

單元測試我們開發(fā)完頁面后一并測試。


Github地址

代碼地址: https://github.com/yangshangwei/o2o

總結

以上是生活随笔為你收集整理的实战SSM_O2O商铺_23【商铺列表】Controller层开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。