查询出的 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())));
本文介绍了一种使用Java Stream API进行SQL查询结果转换的方法,通过具体示例展示了如何将查询到的设备信息列表转换为便于处理的Map结构。
2982

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



