2 回答
TA贡献1825条经验 获得超4个赞
尝试这个:
ArrayList<IncomeChannelCategoryMap> list = entityManager.createQuery(criteriaQuery).getResultList();
List<IncomeChannelCategoryMap> finalList = new ArrayList<>(list.stream().collect(
Collectors.toMap(IncomeChannelCategoryMap::getIncomeChannelCode, Function.identity(), (IncomeChannelCategoryMap i1, IncomeChannelCategoryMap i2) -> {
i1.setLogicalUnitIdent(i1.getLogicalUnitIdent()+","+i2.getLogicalUnitIdent());
return i1;
})).values());
return finalList;
注意:请相应地添加您的 getter 方法,我只是假设您有这些方法名称。
TA贡献1802条经验 获得超5个赞
您应该使用本机查询方法,正如我在上一个问题中建议的那样:
public List<IncomeChannelCategoryMap> allIncomeChannels(final List<String> list) {
List<Object[]> resultList = entityManager.createNativeQuery(
"select income_channel_code, logicalunit_code, string_agg(logicalunitident,',') idents, keyword from r_income_channel_map where income_channel_code in (:codes) group by logicalunit_code, income_channel_code, keyword")
.setParameter("codes", list).getResultList();
return resultList.stream().map(IncomeChannelCategoryMap::new).collect(Collectors.toList());
}
您需要将此构造函数添加到您的IncomeChannelCategoryMap类中:
IncomeChannelCategoryMap(Object[] objects) {
this.incomeChannelCode = (String) objects[0];
this.logicalUnitCode = (String) objects[1];
this.logicalUnitIdent = (String) objects[2];
this.keyword = (String) objects[3];
}
添加回答
举报