查询出的 sql 结构
id | name | deviceId |
---|---|---|
1 | 传感器 | 1 |
1 | 传感器 | 2 |
实现代码
List<AlarmRulesResponse> responses = devicesInfoMapper.getAllAlarmRules();
//将list 转为map key为设备类型id,value为设备id list
Map<Integer, Set<Integer>> map = responses.stream()
.collect(Collectors.groupingBy(AlarmRulesResponse::getId,
Collectors.mapping(AlarmRulesResponse::getDeviceId, Collectors.toSet())));