zoukankan      html  css  js  c++  java
  • shop--8.商品类别--批量操作--删除(后端)

    dao层

    /**
         * 根据productCategoryId和shopId删除商品类别
         * @param productCategoryId
         * @param shopId
         * @return
         */
        public int deleteProductCategory(@Param("productCategoryId") long productCategoryId,
                                         @Param("shopId") long shopId);
    

      

    <delete id="deleteProductCategory" parameterType="java.lang.Long">
            DELETE
            FROM product_category
            WHERE
            product_category_id=#{productCategoryId}
            AND
            shop_id=#{shopId}
        </delete>
    

      

    service层

        /**
         * 将此商品类别下的商品的类别id置为空,在删除掉该商品类别
         * @param productCategoryId
         * @param shopId
         * @return
         */
        public ProductCategoryExecution deleteProductCategory(long productCategoryId, long shopId);
    

      

    impl

       @Override
        @Transactional
        public ProductCategoryExecution deleteProductCategory(long productCategoryId, long shopId) {
            //将此商品类别下的商品的商品类别置为null
    
            try{
                int effectNum = productCategoryDao.deleteProductCategory( productCategoryId, shopId );
                if(effectNum <= 0){
                    throw new ProductCategoryException( "商品类别删除失败" );
                }else{
                    return new ProductCategoryExecution(ProductCategoryEnum.SUCCESS);
                }
            }catch (Exception e){
                throw new ProductCategoryException("delete productCategory Error: " + e.getMessage() );
            }
        }
    

      

    controller层

    /**
         * 批量删除商品类别
         * @param productCategoryId
         * @param request
         * @return
         */
        @RequestMapping(value="/removeproductcategory", method=RequestMethod.POST)
        @ResponseBody
        public Map<String, Object> removeProductCategory(Long productCategoryId, HttpServletRequest request){
            Map<String, Object> modelMap = new HashMap<>();
            if(productCategoryId != null && productCategoryId > 0){
                try{
                    /*Shop currentShop = (Shop) request.getSession().getAttribute("currentShop");*/
                    Shop currentShop = new Shop();
                    currentShop.setShopId(1L);
                    ProductCategoryExecution productCategoryExecution =
                            productCategoryService.deleteProductCategory( productCategoryId, currentShop.getShopId() );
                    if(productCategoryExecution.getState() == ProductCategoryEnum.SUCCESS.getState()){
                        modelMap.put("success", true);
                    }else{
                        modelMap.put( "success", false );
                        modelMap.put("errMsg", productCategoryExecution.getStateInfo());
                    }
    
                } catch(ProductCategoryException e){
                    modelMap.put( "success", false );
                    modelMap.put("errMsg", e.toString());
                    return modelMap;
                }
            } else{
                modelMap.put( "success", false );
                modelMap.put("errMsg", "请至少选择一个商品类别");
            }
            return modelMap;
        }
    

      

  • 相关阅读:
    机器学习(深度学习)
    机器学习(六)
    机器学习一-三
    Leetcode 90. 子集 II dfs
    Leetcode 83. 删除排序链表中的重复元素 链表操作
    《算法竞赛进阶指南》 第二章 Acwing 139. 回文子串的最大长度
    LeetCode 80. 删除有序数组中的重复项 II 双指针
    LeetCode 86 分割链表
    《算法竞赛进阶指南》 第二章 Acwing 138. 兔子与兔子 哈希
    《算法竞赛进阶指南》 第二章 Acwing 137. 雪花雪花雪花 哈希
  • 原文地址:https://www.cnblogs.com/SkyeAngel/p/8934234.html
Copyright © 2011-2022 走看看