一开始报错如下:
Cannot read properties of null (reading 'forEach')`
原因是返回的属性分组没有关联属性,即attrs: null,所以遍历失败
评论区说可以在前端检查,我试了一下还是报错如下
"TypeError: Cannot read properties of undefined (reading 'attrId')"
前端真的头大,折腾半天最后还是在后端检查null才成功
//2、查询所有属性
return attrGroupEntities.stream().map(group -> {AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();BeanUtils.copyProperties(group, attrsVo);List<AttrEntity> attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId());attrsVo.setAttrs(attrs);return attrsVo;
}).filter(item -> item.getAttrs() != null).collect(Collectors.toList());