使用Map<GroupID, List<Data>>。
Map<Long, List<Data>> groups = new HashMap<Long, List<Data>>();
while (resultSet.next()) {
Long groupId = resultSet.getLong("groupId");
String col1 = resultSet.getString("col1");
String col2 = resultSet.getString("col2");
// ...
List<Data> group = groups.get(groupId);
if (group == null) {
group = new ArrayList<Data>();
groups.put(groupId, group);
}
group.add(new Data(groupId, col1, col2 /* ... */));
}
Run Code Online (Sandbox Code Playgroud)
您也可以使其成为另一个(父)Bean的属性。
| 归档时间: |
|
| 查看次数: |
3278 次 |
| 最近记录: |