Java之品优购课程讲义_day06(8)

5.1.1 显示 SKU列表
goods_edit.html 页面上绑定 SKU 列表

<table  class="table  table-bordered  table-striped  table-hover  dataTable">

<thead>

<tr>

<th  class="sorting"  ng-repeat="item  in entity.goodsDesc.specificationItems">{{item.attributeName}}</th>
<th  class="sorting">价格</th>

<th  class="sorting">库存</th>

<th  class="sorting">是否启用</th>

<th  class="sorting">是否默认</th>

</tr>

</thead>

<tbody>

<tr  ng-repeat="pojo  in  entity.itemList">

<td  ng-repeat="item  in  entity.goodsDesc.specificationItems">

{{pojo.spec[item.attributeName]}}

</td>

<td>

<input  class="form-control" ng-model="pojo.price"    placeholder="价格

">

</td>

<td>

<input  class="form-control"  ng-model="pojo.num"  placeholder="库存数量">

</td>

<td>

<input  type="checkbox"  ng-model="pojo.status"  ng-true-value="1" ng-false-value="0"  >

</td>

<td>

<input  type="checkbox"  ng-model="pojo.isDefault"  ng-true-value="1" ng-false-value="0">

</td>

</tr>

</tbody>

</table>

删除掉原来的测试用的表达式

5.1 后端代码
(1)在 GoodsServiceImpl 添加属性

@Autowired

private  TbItemMapper  itemMapper;

@Autowired
private  TbBrandMapper  brandMapper;

@Autowired

private  TbItemCatMapper  itemCatMapper;

@Autowired

private  TbSellerMapper  sellerMapper;
(2)修改 GoodsServiceImpl 的 add 方法,增加代码,实现对 SKU 商品信息的保存

/**
  • 增 加
*/ @Override
public  void  add(Goods  goods)  {
goods.getGoods().setAuditStatus("0"); goodsMapper.insert(goods.getGoods());  //插入商品表

goods.getGoodsDesc().setGoodsId(goods.getGoods().getId());

goodsDescMapper.insert(goods.getGoodsDesc());//插入商品扩展数据

for(TbItem  item  :goods.getItemList()){

//标题

String  title=  goods.getGoods().getGoodsName(); Map<String,Object>  specMap  =  JSON.parseObject(item.getSpec()); for(String  key:specMap.keySet()){
title+="  "+  specMap.get(key);
}
item.setTitle(title); item.setGoodsId(goods.getGoods().getId());//商品 SPU 编号

item.setSellerId(goods.getGoods().getSellerId());//商家编号

item.setCategoryid(goods.getGoods().getCategory3Id());//商品分类编号(3 级)

item.setCreateTime(new  Date());//创建日期 item.setUpdateTime(new  Date());//修改日期
//品牌名称TbBrand  brand  =
brandMapper.selectByPrimaryKey(goods.getGoods().getBrandId());

item.setBrand(brand.getName());

//分类名称

TbItemCat  itemCat  = itemCatMapper.selectByPrimaryKey(goods.getGoods().getCategory3Id());

item.setCategory(itemCat.getName());

//商家名称TbSeller  seller  =
sellerMapper.selectByPrimaryKey(goods.getGoods().getSellerId());

item.setSeller(seller.getNickName());

//图片地址(取 spu 的第一个图片)

List<Map>  imageList  =  JSON.parseArray(goods.getGoodsDesc().getItemImages(), Map.class)  ;

if(imageList.size()>0){

item.setImage  (  (String)imageList.get(0).get("url"));

}

itemMapper.insert(item);

}

}

转载于:https://blog.51cto.com/13517854/2163447

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值