如何在bean类中使用groupBy。

huangapple 未分类评论58阅读模式
英文:

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>

&gt; 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&lt;models.ClusterResources&gt;**



public static List&lt;ClusterResources&gt; getClusterLeaderByEmpId(int cluster_id) {
    List&lt;ClusterResources&gt; clusterLeaders = Ebean.find(ClusterResources.class)
            .where()
            .eq(&quot;cluster_id&quot;, cluster_id)
            .groupBy(&quot;cluster_leader&quot;)
            .findList();
        if (clusterLeaders == null)
            clusterLeaders = new ArrayList&lt;&gt;();
    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&#39;s a bit hard to know what you want to achieve, but Ebean will generally add &quot;group by&quot; automatically when needed, e.g. if you select something that needs grouping:

    .select(&quot;cluster_leader, MAX(cluster_value)&quot;)

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>



huangapple
  • 本文由 发表于 2020年6月29日 15:03:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/62632855.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定