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     }
  • 相关阅读:
    并发学习之:不使用内核对象同步的并发队列
    破解C#的readonly只读字段
    并发学习之:乱序执行和内存屏障
    并发学习之:缓存一致性
    并发学习之:Keyed Events(没看懂,要调试下才能明白,伤心!)
    静态和非静态的访问
    asc2码
    学习报告
    11号学习总结
    9号总结
  • 原文地址:https://www.cnblogs.com/windbag7/p/9416103.html
Copyright © 2011-2022 走看看