2 回答

TA貢獻(xiàn)1825條經(jīng)驗 獲得超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;
注意:請相應(yīng)地添加您的 getter 方法,我只是假設(shè)您有這些方法名稱。

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
您應(yīng)該使用本機(jī)查詢方法,正如我在上一個問題中建議的那樣:
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());
}
您需要將此構(gòu)造函數(shù)添加到您的IncomeChannelCategoryMap類中:
IncomeChannelCategoryMap(Object[] objects) {
this.incomeChannelCode = (String) objects[0];
this.logicalUnitCode = (String) objects[1];
this.logicalUnitIdent = (String) objects[2];
this.keyword = (String) objects[3];
}
添加回答
舉報