谷粒商城—商品服务—属性分组+品牌管理(70~75)"/>
谷粒商城—商品服务—属性分组+品牌管理(70~75)
一.SPU 和 SKU 概念:
二.商品数据库 表结构 梳理:
三.根据 三级分类 id ,查询 基本属性 列表
1)请求:(http://127.0.0.1:88/api/product/attrgroup/list/225)
2)Controller:
/*** 商品管理,根据 三级分类 id ,查询 基本属性 列表*/@RequestMapping("/list/{catelogId}")public R list(@RequestParam Map<String, Object> params,@PathVariable Long catelogId) {PageUtils page = attrGroupService.queryPage(params, catelogId);return R.ok().put("page", page);}
3)Service:
select * from pms_attr_group where catelog_id = ? and (attr_group_id = key or attr_group_name like key)
@Overridepublic PageUtils queryPage(Map<String, Object> params, Long catelogId) {//查询所有if (catelogId == 0) {IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),new QueryWrapper<AttrGroupEntity>());return new PageUtils(page);} else {//select * from pms_attr_group where catelog_id = ? and (attr_group_id = key or attr_group_name like key)QueryWrapper<AttrGroupEntity> queryWrapper = new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId);String key = (String) params.get("key");if (!StringUtils.isEmpty(key)) {queryWrapper.and(age -> {age.eq("attr_group_id", key).or().like("attr_group_name", key);});}IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),queryWrapper);return new PageUtils(page);}}
4)查询 SQL:
a:打印 SQL:
logging:level:com.guigu.gulimail.product.dao: debug
b:在 sql:
-- 2 2021-04-01 11:20:36.546 DEBUG 5462 --- [o-11000-exec-10] c.g.g.p.dao.AttrGroupDao.selectPage : ==>SELECT attr_group_id,attr_group_name,sort,descript,icon,catelog_idFROM pms_attr_groupWHERE (catelog_id = 225)LIMIT 10;
-- ==> Total: 3
c:表结构:
5)结果报文:
{"msg": "success","code": 0,"page": {"totalCount": 3,"pageSize": 10,"totalPage": 1,"currPage": 1,"list": [{"attrGroupId": 1,"attrGroupName": "信息","sort": 0,"descript": "荣耀","icon": ".jpg","catelogId": 225,"catelogPath": null},{"attrGroupId": 2,"attrGroupName": "基本信息","sort": 0,"descript": "华为","icon": ".jpg","catelogId": 225,"catelogPath": null},{"attrGroupId": 4,"attrGroupName": "芯片","sort": 0,"descript": "CPU型号","icon": ".jpg","catelogId": 225,"catelogPath": null}]}
}
四.查询 属性分组 完整信息(包含 属性 完整路径)
1)请求:(http://127.0.0.1:88/api/product/attrgroup/info/225)
2)Controller:
/*** 查询 属性分组 完整信息。*/@RequestMapping("/info/{attrGroupId}")//@RequiresPermissions("product:attrgroup:info")public R info(@PathVariable("attrGroupId") Long attrGroupId) {//查询 属性分组 完整信息。AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);/*** 根据 三级分类 id ,查找完整路径,* 【父 子 孙】*/Long catelogId = attrGroup.getCatelogId();Long[] paths = categoryService.findCatelogPath(catelogId);attrGroup.setCatelogPath(paths);return R.ok().put("attrGroup", attrGroup);}
3)Service:
//[2,25,225]@Overridepublic Long[] findCatelogPath(Long attrGroupId) {ArrayList<Long> list = new ArrayList<>();List<Long> parentPath = findParentPath(attrGroupId, list);//反转 list 元素Collections.reverse(parentPath);//将 集合 转换为 数组。return (Long[]) parentPath.toArray(new Long[parentPath.size()]);}/*** 递归查找 所有菜单的子菜单*/private List<Long> findParentPath(Long catelogId, List<Long> paths) {CategoryEntity byId = this.getById(catelogId);//收集 当前节点 id。paths.add(catelogId);// 如果 当前节点 有 父节点。if (byId.getParentCid() != 0) {List<Long> parentPath = findParentPath(byId.getParentCid(), paths);}return paths;}
五.安装 MybatisPlus 分页插件:
/*** @Author zhangsan* @Date 2021/3/16 8:00 下午* @Version 1.0*/
@EnableTransactionManagement
@Configuration
@MapperScan("com.guigu.gulimail.product.dao")
public class MybatisPlusPageConfig {@Beanpublic PaginationInterceptor paginationInterceptor() {PaginationInterceptor paginationInterceptor = new PaginationInterceptor();// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false// paginationInterceptor.setOverflow(false);// 设置最大单页限制数量,默认 500 条,-1 不受限制// paginationInterceptor.setLimit(500);// 开启 count 的 join 优化,只针对部分 left joinpaginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));return paginationInterceptor;}
}
更多推荐
谷粒商城—商品服务—属性分组+品牌管理(70~75)
发布评论