Explorar o código

修改GoodsAttrServiceImpl.java中的updateGoodsAttr方法,将该方法的循环调用数据库接口优化

liu hai 2 meses
pai
achega
60048ee125

+ 4 - 1
src/main/java/com/sqx/modules/goods/service/impl/GoodsAttrServiceImpl.java

@@ -10,6 +10,7 @@ import com.sqx.modules.goods.service.GoodsAttrValueService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @Service
@@ -23,12 +24,14 @@ public class GoodsAttrServiceImpl extends ServiceImpl<GoodsAttrDao, GoodsAttr> i
         //删除之前的值
         goodsAttrValueService.deleteGoodsAttrValueByGoodsId(goodsAttr.getGoodsId());
         //放入新值
+        ArrayList<GoodsAttrValue> goodsAttrValues = new ArrayList<>();
         for (GoodsAttrValue v : goodsAttr.getAttrValue()) {
             v.setId(null);
             v.setGoodsId(goodsAttr.getGoodsId());
             v.setAttrId(goodsAttr.getId());
-            goodsAttrValueService.save(v);
+            goodsAttrValues.add(v);
         }
+        goodsAttrValueService.saveBatch(goodsAttrValues);
         baseMapper.delete(new QueryWrapper<GoodsAttr>().eq("goods_id",goodsAttr.getGoodsId()));
         baseMapper.insert(goodsAttr);
         return 1;