分布式电商项目三十二:商品服务-新增分组功能

新增分组功能

前端页面的新增分组功能,为其提供后端实现:
在这里插入图片描述
首先修改一个后端返回的问题
在分组没有子分类的时候,页面依然会显示有白框。这是因为第三级分类中会出现children字段,并且为空,需要在后端返回的时候,为空则不显示。
在这里插入图片描述
来到对应的实体类,添加注解即可:

package com.lastingwar.mall.product.entity;
/**
 * 商品三级分类
 * 
 * @author yhm
 * @email 403627000@qq.com
 * @date 2020-05-29 16:37:08
 */
@Data
@TableName("pms_category")
public class CategoryEntity implements Serializable {
   
	private static final long serialVersionUID = 1L;
...
	/**
	 * 子分类
	 */
	@JsonInclude(JsonInclude.Include.NON_EMPTY)
	@TableField(exist = false)
	private List<CategoryEntity> children;
}

之后重启服务,来到前端页面即可发现白框消失了:
在这里插入图片描述
之后测试新增功能:
在这里插入图片描述
至此测试完成,修改和删除功能也是正常使用的。
在这里插入图片描述
路径的正确回显
在点击修改时,下面的路径无法正确回显,需要后端提高一个查询路径的接口
在这里插入图片描述
首先来到实体类,添加分类路径的字段;

	/**
	 * 分类的三级路径
	 */
	@TableField(exist = false)
	private Long[] catalogPath;

之后来到控制层AttrGroupController,添加调用一个返回路径的方法:

   /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    //@RequiresPermissions("product:attrgroup:info")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
   
		AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);

		//分组所属分类的ID
        Long catelogId = attrGroup.getCatelogId();
        //使用名称为findCatelogPath的方法找到全部的路径ID
        Long[] path =categoryService.findCatelogPath(catelogId);
        //将路径添加进入
        attrGroup.setCatalogPath(path);

        return R.ok().put("attrGroup", attrGroup);
    }

之后添加这个方法到service中:

package com.lastingwar.mall.product.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.lastingwar.common.utils.PageUtils;
import com.lastingwar.mall.product.entity.CategoryEntity;

import java.util.List
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值