java - Java android房间对象映射
问题描述
我有这门课:
public class RelationshipsOrderAndBins {
@Embedded
public RowEntity order;
@Relation(parentColumn = "order_id", entityColumn = "orderId",entity = LoadingRow.class)
public List<LoadingRow> bins;
}
让LiveData<List<RelationshipsOrderAndBins>>
我这样做:
@Query("SELECT * FROM orders INNER JOIN bin ON orders.order_id= bin.orderId")
LiveData<List<RelationshipsOrderAndBins>> geRelationshipsOrderAndBins();
而且我不知道如何转换为:HashMap<Integer,List,Loadings>
关键在哪里order.getId()
解决方案
要将 a 转换List
为 a Map
,您可以使用流并使用收集它Collectors.toMap
List<RelationshipsOrderAndBins> list = new ArrayList<RelationshipsOrderAndBins>();
Map<Integer, List<LoadingRow>> map = list.stream()
.collect(Collectors.toMap(
r -> r.getOrder().getId(),
r -> r.getBins()));
推荐阅读
- spring - 当我在 springfrmework 中运行我的项目时出现错误
- vue.js - 将 Nuxt.js SPA 模式更改为通用模式
- php - laravel 7 Auth::routes 不适用于禁用注册和密码重置
- python - Python。如何计算嵌套 for 循环中的除数?
- openresty - 多重重定向/并行重定向 - Google 如何实现?
- ios - Xcode Archive 制作了一个空的 Products 文件夹:验证内容按钮是灰色的
- javascript - 如何从 Cefsharp EvaluateScriptAsync 获取返回值
- html - 如何隐藏所有 safari 浏览器的 CSS 样式
- android - 指定 Android Lint 版本
- flutter - 如何保存列表