(1)spu相关业务介绍
销售属性
销售属性,就是商品详情页右边,可以通过销售属性来定位一组spu下的哪款sku。可以让当前的商品详情页,跳转到自己的“兄弟”商品。
一般每种商品的销售属性不会太多,大约1-4种。整个电商的销售属性种类也不会太多,大概10种以内。比如:颜色、尺寸、版本、套装等等。不同销售属性的组合也就构成了一个spu下多个sku的结构。
因此,在制作spu之前要先确定当前商品有哪些销售属性!
spu数据结构图
(2)列表查询功能开发
当选择最后一个时:会发送请求
查询的是单个表:
实体类:SkuInfo
package com.atguigu.gmall.model.product;import com.atguigu.gmall.model.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import java.math.BigDecimal;
import java.util.List;/*** <p>* SkuInfo* </p>**/
@Data
@ApiModel(description = "SkuInfo")
@TableName("sku_info")
public class SkuInfo extends BaseEntity {public SkuInfo(){}public SkuInfo(Long skuId){setId(skuId);}// 判断去重的话,自动调用equals 方法。public boolean equals(SkuInfo skuInfo){return getId().equals(skuInfo.getId());}private static final long serialVersionUID = 1L;@ApiModelProperty(value = "商品id")@TableField("spu_id")private Long spuId;@ApiModelProperty(value = "价格")@TableField("price")private BigDecimal price;@ApiModelProperty(value = "sku名称")@TableField("sku_name")private String skuName;@ApiModelProperty(value = "商品规格描述")@TableField("sku_desc")private String skuDesc;@ApiModelProperty(value = "重量")@TableField("weight")private String weight;@ApiModelProperty(value = "品牌(冗余)")@TableField("tm_id")private Long tmId;@ApiModelProperty(value = "三级分类id(冗余)")@TableField("category3_id")private Long category3Id;@ApiModelProperty(value = "默认显示图片(冗余)")@TableField("sku_default_img")private String skuDefaultImg;@ApiModelProperty(value = "是否销售(1:是 0:否)")@TableField("is_sale")private Integer isSale;@TableField(exist = false)List<SkuImage> skuImageList;@TableField(exist = false)List<SkuAttrValue> skuAttrValueList;@TableField(exist = false)List<SkuSaleAttrValue> skuSaleAttrValueList;
}
创建mapper:SpuInfoMapper
@Mapper
public interface SpuInfoMapper extends BaseMapper<SpuInfo> {}
继续再ManageService添加
/*** spu分页查询* @param pageParam* @param spuInfo* @return*/
IPage<SpuInfo> getSpuInfoPage(Page<SpuInfo> pageParam, SpuInfo spuInfo);
实现类 ManageServiceImpl
@Autowired
private SpuInfoMapper spuInfoMapper;@Override
public IPage<SpuInfo> getSpuInfoPage(Page<SpuInfo> pageParam, SpuInfo spuInfo) {QueryWrapper<SpuInfo> queryWrapper = new QueryWrapper<>();queryWrapper.eq("category3_id", spuInfo.getCategory3Id());queryWrapper.orderByDesc("id");return spuInfoMapper.selectPage(pageParam, queryWrapper);
}
创建控制器SpuManageController
@RestController // @ResponseBody + @Controller
@RequestMapping("admin/product")
public class SpuManageController {@Autowiredprivate ManageService manageService;// 根据查询条件封装控制器// springMVC 的时候,有个叫对象属性传值 如果页面提交过来的参数与实体类的参数一致,// 则可以使用实体类来接收数据// http://api.gmall.com/admin/product/1/10?category3Id=61// @RequestBody 作用 将前台传递过来的json{"category3Id":"61"} 字符串变为java 对象。@GetMapping("{page}/{size}")public Result getSpuInfoPage(@PathVariable Long page,@PathVariable Long size,SpuInfo spuInfo){// 创建一个Page 对象Page<SpuInfo> spuInfoPage = new Page<>(page,size);// 获取数据IPage<SpuInfo> spuInfoPageList = manageService.getSpuInfoPage(spuInfoPage, spuInfo);// 将获取到的数据返回即可!return Result.ok(spuInfoPageList);}
}