英文:
How to use groupBy in bean class
问题
我有这段代码,但在运行时出现了如下错误...
**无法找到符号
符号: 方法 groupBy(java.lang.String)
位置: 接口 com.avaje.ebean.ExpressionList<models.ClusterResources>**
public static List<ClusterResources> getClusterLeaderByEmpId(int cluster_id) {
List<ClusterResources> clusterLeaders = Ebean.find(ClusterResources.class)
.where()
.eq("cluster_id", cluster_id)
.groupBy("cluster_leader")
.findList();
if (clusterLeaders == null)
clusterLeaders = new ArrayList<>();
return clusterLeaders;
}
<details>
<summary>英文:</summary>
> I have this code but while running i m getting error like...
**cannot find symbol
symbol: method groupBy(java.lang.String)
location: interface com.avaje.ebean.ExpressionList<models.ClusterResources>**
public static List<ClusterResources> getClusterLeaderByEmpId(int cluster_id) {
List<ClusterResources> clusterLeaders = Ebean.find(ClusterResources.class)
.where()
.eq("cluster_id", cluster_id)
.groupBy("cluster_leader")
.findList();
if (clusterLeaders == null)
clusterLeaders = new ArrayList<>();
return clusterLeaders;
}
</details>
# 答案1
**得分**: 0
没有看到你的模型 ClusterResources,有点难以知道你想要实现什么,但是 Ebean 通常会在需要时自动添加 "group by",例如,如果你选择了需要分组的内容:
.select("cluster_leader, MAX(cluster_value)")
请查看以下链接:
[Ebean 聚合][1] 和 [Ebean 选择][2]。
[1]: https://ebean.io/docs/query/aggregation
[2]: https://ebean.io/docs/query/select
<details>
<summary>英文:</summary>
without seeing your model ClusterResources it's a bit hard to know what you want to achieve, but Ebean will generally add "group by" automatically when needed, e.g. if you select something that needs grouping:
.select("cluster_leader, MAX(cluster_value)")
Check out these links:
[Ebean aggregation][1] and [Ebean select][2]
[1]: https://ebean.io/docs/query/aggregation
[2]: https://ebean.io/docs/query/select
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论