gpt4 book ai didi

Java android room 对象来映射

转载 作者:行者123 更新时间:2023-12-01 23:52:54 25 4
gpt4 key购买 nike

我有这门课:

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()

最佳答案

要将List转换为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()));

关于Java android room 对象来映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com