• shop--7.店铺信息编辑--Controller层


    在Controller层需要两个方法,一个就是获取店铺信息

    getShopById

     1   /**
     2     * 根据店铺信息获取店铺
     3     * @param request
     4     * @return
     5     */
     6    @RequestMapping(value="/getshopbyid", method=RequestMethod.GET)
     7    @ResponseBody
     8    private Map<String, Object> getShopById(HttpServletRequest request){
     9        Map<String, Object> modelMap = new HashMap<>();
    10        Long shopId = HttpServletRequestUtil.getLong( request, "shopId" );
    11        if(shopId > -1){//大于-1就证明前端传过来了
    12            try{
    13                Shop shop = shopService.getShopByShopId( shopId );
    14                List<Area> areaList = areaService.getAreaList();//因为区域信息是可以更改的,所以需要获取
    15                modelMap.put("shop", shop);
    16                modelMap.put( "areaList", areaList );
    17                modelMap.put( "success", true );
    18            } catch(Exception e){
    19                modelMap.put("success", false);
    20                modelMap.put("errMsg", e.toString());
    21            }
    22  
    23        }else{
    24            modelMap.put("success", false);
    25            modelMap.put( "errMsg", "empty shopId" );
    26        }
    27        return modelMap;
    28    }


    更改店铺信息(和注册店铺相似)

      1.先看传递过来的验证码

      2.接受从前台传过来的shopStr的字符串

      3.将shopStr转成Shop实体对象

      4.前台传过来的文件流解析成CommonsMultipartFile里面去

      5.最后将Shop对象和文件流使用Service层方法添加

      

     1 @RequestMapping(value = "/modifyshop", method = RequestMethod.POST)
     2     @ResponseBody
     3     private Map<String, Object> modifyShop(HttpServletRequest request) {
     4         Map<String, Object> modelMap = new HashMap<String, Object>();
     5         if (!CodeUtil.checkVerifyCode(request)) {
     6             modelMap.put("success", false);
     7             modelMap.put("error", "输入了错误的验证码");
     8             return modelMap;
     9         }
    10         // 1.接受并转化相应的参数,包括店铺信息以及图片信息
    11         String shopStr = HttpServletRequestUtil.getString(request, "shopStr");
    12         ObjectMapper mapper = new ObjectMapper();
    13         Shop shop = null;
    14         try {
    15             shop = mapper.readValue(shopStr, Shop.class);
    16         } catch (Exception e) {
    17             modelMap.put("success", false);
    18             modelMap.put("errMsg", e.getMessage());
    19             return modelMap;
    20         }
    21         CommonsMultipartFile shopImg = null;
    22         CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
    23                 request.getSession().getServletContext());
    24         // 如果文件上传有值的话
    25         if (commonsMultipartResolver.isMultipart(request)) {
    26             MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
    27             shopImg = (CommonsMultipartFile) multipartHttpServletRequest.getFile("shopImg");
    28         }//图片可上传可不上传的 非空判断可以去掉
    29         // 2.修改店铺信息
    30         if (shop != null && shop.getShopId() != null) {//确保shopId不为空
    31             ShopExecution se;
    32             try {
    33                 // 当文件为空时 直接传入空值
    34                 if (shopImg == null) {
    35                     se = shopService.modifyShop(shop, null, null);
    36                 } else {
    37                     se = shopService.modifyShop(shop, shopImg.getInputStream(), shopImg.getOriginalFilename());
    38                 }
    39                 // se = shopService.modifyShop(shop,
    40                 // shopImg.getInputStream(),shopImg.getOriginalFilename()); 换成了上面这个if else 判断
    41                 if (se.getState() == ShopStateEnum.SUCCESS.getState()) {//CHECK->SUCCESS
    42                     modelMap.put("success", true);
    43                 } else {
    44                     modelMap.put("errMsg", se.getStateInfo());
    45                 }
    46             } catch (ShopOperationException e) {
    47                 modelMap.put("success", false);
    48                 modelMap.put("errMsg", e.getMessage());
    49             } catch (IOException e) {
    50                 modelMap.put("success", false);
    51                 modelMap.put("errMsg", e.getMessage());
    52             }
    53 
    54             return modelMap;
    55         } else {
    56             modelMap.put("success", false);
    57             modelMap.put("errMsg", "请输入店铺ID");
    58             return modelMap;
    59         }
    60         // 3.返回结果
    61     }

    顺便在注册方法中Session

       通过Session获取登录后的user信息

                PersonInfo owner = (PersonInfo) request.getSession().getAttribute("user");
                shop.setOwner(owner);

      获取user信息后设置user可操作的店铺列表

    1           @SuppressWarnings("unchecked")
    2           List<Shop> shopList = (List<Shop>) request.getSession().getAttribute("shopList");
    3           if (shopList == null || shopList.size() == 0) {
    4           shopList = new ArrayList<Shop>();
    5           }
    6           shopList.add(se.getShop());
    7           request.getSession().setAttribute("shopList", shopList);
  • 相关阅读:
    Salesforce和SAP Netweaver里数据库表的元数据设计
    Salesforce平台支持多租户Multi tenant的核心设计思路
    S/4HANA生产订单增强WORKORDER_UPDATE方法BEFORE_UPDATE参数分析
    S/4HANA生产订单的标准状态和透明工厂原型状态的映射
    1048. Find Coins (25)
    1101. Quick Sort (25)
    1009. Product of Polynomials (25)
    pta 奇数值结点链表&&单链表结点删除
    1007. Maximum Subsequence Sum (25)
    1006. Sign In and Sign Out (25)
  • 原文地址:https://www.cnblogs.com/windbag7/p/9385390.html
Copyright © 2020-2023  润新知