document
API test

获取属性分组下的属性

GET
http://localhost:88/api/product/attrgroup/:attrGroupId/attr/relation

API description

获取属性分组下所有的属性

Request Parameters

parameter
type
description
required
attrGroupId
int
示例:1
required

Response Parameters

parameter
type
description
required
msg
string
示例:success
required
code
int
示例:0
required
data
array
数据列表
required
attrId
int
示例:7
required
attrName
string
示例:入网型号
required
searchType
int
示例:0
required
valueType
int
示例:0
required
icon
string
示例:xxx
required
valueSelect
string
示例:A2217;C3J;以官网信息为准
required
attrType
int
示例:1
required
enable
int
示例:1
required
catelogId
int
示例:225
required
showDesc
int
示例:0
required

Description or Example

# 核心代码 ```java @RequestMapping("/{attrGroupId}/attr/relation") public R getAttrsByAttrGroup(@PathVariable("attrGroupId") Long attrGroupId) { List<AttrEntity> attrEntities = attrGroupService.getAllAttrsByAttrGroup(attrGroupId); return R.ok().put("data", attrEntities); } ``` ```java @Override public List<AttrEntity> getAllAttrsByAttrGroup(Long attrGroupId) { // 获取所有的属性id List<Long> attrIds = relationService.getAllAttrIdsByAttrGroups(attrGroupId); // 如果属性IDS为空或集合为空, 返回null避免空指针异常 if (attrIds == null || attrIds.isEmpty()) return null; else // 获取详细信息 return attrService.getBaseMapper().selectBatchIds(attrIds); } ``` ```java @Override public List<Long> getAllAttrIdsByAttrGroups(Long... attrGroupIds) { LambdaQueryWrapper<AttrAttrgroupRelationEntity> wrapper = new LambdaQueryWrapper<>(); wrapper.in(AttrAttrgroupRelationEntity::getAttrGroupId, Arrays.asList(attrGroupIds)); // 找到所有的属性分组与属性的关系 List<AttrAttrgroupRelationEntity> relationEntities = this.baseMapper.selectList(wrapper); // 返回所有的属性ID return relationEntities.stream().map(AttrAttrgroupRelationEntity::getAttrId).collect(Collectors.toList()); } ```