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);
}
}