新增分组功能
前端页面的新增分组功能,为其提供后端实现:
首先修改一个后端返回的问题
在分组没有子分类的时候,页面依然会显示有白框。这是因为第三级分类中会出现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