zoukankan      html  css  js  c++  java
  • shop--10.商品--解除商品与某商品类别的关联的实现

    ProductDao.java

    1     /**
    2      * 删除商品类别之前,将商品类别Id置为空
    3      * 
    4      * @param productCategoryId
    5      * @return
    6      */
    7     int updateProductCategoryToNull(long productCategoryId);

    ProductDao.xml

        <update id="updateProductCategoryToNull" parameterType="Long">
            UPDATE
            tb_product
            SET
            product_category_id = null
            WHERE
            product_category_id = 
            #{productCategoryId}
        </update>

    接着将之前的ProductCategoryServiceImpl中的删除给完善好

     1     //由于先将商品类别 商品id置为空 再删除 分为两步 所以使用事务
     2     @Transactional
     3     @Override
     4     public ProductCategoryExecution deleteProductCategory(long productCategoryId, long shopId)
     5             throws ProductCategoryOperationException {
     6         // TODO 将此商品类别下的商品Id置为空
     7         //解除tb_product里的商品与该productcategoryId的关联
     8         try {
     9             int effectedNum = productDao.updateProductCategoryToNull(productCategoryId);
    10             if(effectedNum < 0) {
    11                 throw new ProductCategoryOperationException("商品类别更新失败");
    12             }
    13         }catch (Exception e) {
    14             throw new ProductCategoryOperationException("deleteProductCategory error" + e.getMessage());
    15         }
    16         //删除该productCategory
    17         try {
    18             int effectedNum = productCategoryDao.deleteProductCategory(productCategoryId, shopId);
    19             if(effectedNum <= 0) {
    20                 throw new ProductCategoryOperationException("商品类别删除失败");
    21             }else {
    22                 return new ProductCategoryExecution(ProductCategoryStateEnum.SUCCESS);
    23             }
    24         }catch (Exception e) {
    25             throw new ProductCategoryOperationException("deleteProductCategory error :" + e.getMessage());
    26         }
    27     }
  • 相关阅读:
    JS正则手机靓号处理AB ABAB AABB
    url参数中有+、空格、=、%、&、#等特殊符号的问题解决
    LigerUI 使用教程表格篇
    JS获取地址栏参数
    手机端meta
    最大连续子序列 hdu 1231
    I NEED A OFFER! hdu1203(背包)
    Bookshelf 2 poj3628(01背包/DFS)
    Charm Bracelet poj3624(01背包)
    985的方格难题(dp)
  • 原文地址:https://www.cnblogs.com/windbag7/p/9416103.html
Copyright © 2011-2022 走看看