1.添加catelogIds字段
因为我们分组修改页面,实际分类ID显示是一个分类数组

在实体类中添加字段

2.后端实现
controller层
@RequestMapping("/info/{attrGroupId}")
public R info(@PathVariable("attrGroupId") Long attrGroupId){
AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);
//根据当前分类获取其分类父分类组合
attrGroup.setCatelogIds(categoryService.getCatelogIds(attrGroup.getCatelogId()));
return R.ok().put("attrGroup", attrGroup);
}
service层
CategoryServiceImpl
@Override
public Long[] getCatelogIds(Long catelogId) {
ArrayList<Long> arrayList = new ArrayList<>();
return getCategoryArray(catelogId,arrayList);
}
public Long[] getCategoryArray(Long catelogId,ArrayList<Long> arr){
arr.add(catelogId);
CategoryEntity categoryEntity = this.getById(catelogId);
if(categoryEntity.getParentCid() != 0 )
{
getCategoryArray(categoryEntity.getParentCid(),arr);
}
Collections.reverse(arr);
return arr.toArray(new Long[]{});
}
3.测试成功
修改时分类成功带出来了

4.弹窗关闭时分类置为空
如下

添加监听
方法,将分类数组置为空


本文介绍了一个后端功能的实现过程,主要包括在实体类中添加catelogIds字段来存储分类数组,通过service层的方法获取分类及其父分类的组合,并在controller层返回这些数据。测试结果显示,该功能能够正确地展示分类信息。
3706

被折叠的 条评论
为什么被折叠?



