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     }
  • 相关阅读:
    带你破解时间管理的谜题
    学点产品思维(一起拿返现)
    利用MAT玩转JVM内存分析(一)
    JVM利器:Serviceability Agent介绍
    003-005:Java平台相关的面试题
    002-如何理解Java的平台独立性
    001-为什么Java能这么流行
    Redis保证事务一致性,以及常用的数据结构
    敏感词过滤服务的实现
    或许,挂掉的点总是出人意料(hw其实蛮有好感的公司)
  • 原文地址:https://www.cnblogs.com/windbag7/p/9416103.html
Copyright © 2011-2022 走看看