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     }
  • 相关阅读:
    uinty实现玩家尾随鼠标位置平滑旋转角度
    matlab hornerDemo
    【App 开发框架
    mobiscroll手机端插件 好用(时间、日历、颜色)
    朴素的UNIX之-调度器细节
    String与StringBuffer的差别
    用jquery ajax做的select菜单,选中的效果
    Codeforces Round #253 (Div. 2)A. Anton and Letters
    unix环境高级编程——文件i/o
    CSDN的技术问题
  • 原文地址:https://www.cnblogs.com/windbag7/p/9416103.html
Copyright © 2011-2022 走看看