-
Notifications
You must be signed in to change notification settings - Fork 8
15.多级从表数据收集
Bing edited this page Jul 27, 2018
·
1 revision
对象A、B、C。A中有属性b,B中有属性c,通过查询A将其他BC都收集。
List<A> aList = JpaUtil.linq(A.class).list();
if (!aList.isEmpty()) {
Set<String> bIds = JpaUtil.collect(aList, "bId"); //收集aList中的bId属性值
List<B> bList = JpaUtil.linq(B.class)
.collect(C.class, "cId")
.in("id", bIds)
.list();
Map<String, B> bMap = JpaUtil.index(bList);//以主键值为key(如果想自定义,可以用index(bList, "xxx")),B对象为value
for(A a : aList) {// 给A分配B
a.setB(bMap.get(a.getBId()));
}
}