我有这个方法:
public List<IncomeChannelCategoryMap> allIncomeChannels(final List<String> list) {
final CriteriaQuery<IncomeChannelCategoryMap> criteriaQuery = builder.createQuery(IncomeChannelCategoryMap.class);
final Root<IncomeChannelMapEntity> root = criteriaQuery.from(IncomeChannelMapEntity.class);
final List<Selection<?>> selections = new ArrayList<>();
selections.add(root.get(IncomeChannelMapEntity_.incomeChannel).get(IncomeChannelEntity_.code));
selections.add(root.get(IncomeChannelMapEntity_.logicalUnitCode));
selections.add(root.get(IncomeChannelMapEntity_.logicalUnitIdent));
selections.add(root.get(IncomeChannelMapEntity_.keyword));
criteriaQuery.multiselect(selections);
Predicate codePredicate = root.get(IncomeChannelMapEntity_.incomeChannel).get(IncomeChannelEntity_.code).in(list);
criteriaQuery.where(codePredicate);
return entityManager.createQuery(criteriaQuery).getResultList();
}
响应是这样的:
[
{
"incomeChannelCode": "DIRECT_SALES",
"logicalUnitCode": "R_CATEGORY",
"logicalUnitIdent": "7"
},
{
"incomeChannelCode": "DIRECT_SALES",
"logicalUnitCode": "R_CATEGORY",
"logicalUnitIdent": "8"
}
]
我想要实现的是:
{
"incomeChannelCode": "DIRECT_SALES",
"logicalUnitCode": "R_CATEGORY",
"logicalUnitIdent": "7,8"
}
有什么建议我怎样才能实现这个目标?
我尝试过这个,我在一些例子中发现了这一点:
builder.function("group_concat", String.class, root.get(IncomeChannelMapEntity_.logicalUnitIdent));
但这是行不通的。还有其他建议吗?
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class IncomeChannelCategoryMap implements Serializable {
private static final long serialVersionUID = 1L;
private String incomeChannelCode;
private String logicalUnitCode;
private String logicalUnitIdent;
private String keyword;
}
凤凰求蛊
慕后森
相关分类