如何在bean类中使用groupBy。

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

How to use groupBy in bean class

问题

  1. 我有这段代码,但在运行时出现了如下错误...
  2. **无法找到符号
  3. 符号: 方法 groupBy(java.lang.String)
  4. 位置: 接口 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;
}

  1. <details>
  2. <summary>英文:</summary>
  3. &gt; I have this code but while running i m getting error like...
  4. **cannot find symbol
  5. symbol: method groupBy(java.lang.String)
  6. location: interface com.avaje.ebean.ExpressionList&lt;models.ClusterResources&gt;**
  1. public static List&lt;ClusterResources&gt; getClusterLeaderByEmpId(int cluster_id) {
  2. List&lt;ClusterResources&gt; clusterLeaders = Ebean.find(ClusterResources.class)
  3. .where()
  4. .eq(&quot;cluster_id&quot;, cluster_id)
  5. .groupBy(&quot;cluster_leader&quot;)
  6. .findList();
  7. if (clusterLeaders == null)
  8. clusterLeaders = new ArrayList&lt;&gt;();
  9. return clusterLeaders;
  10. }
  1. </details>
  2. # 答案1
  3. **得分**: 0
  4. 没有看到你的模型 ClusterResources,有点难以知道你想要实现什么,但是 Ebean 通常会在需要时自动添加 "group by",例如,如果你选择了需要分组的内容:

.select("cluster_leader, MAX(cluster_value)")

  1. 请查看以下链接:
  2. [Ebean 聚合][1] [Ebean 选择][2]。
  3. [1]: https://ebean.io/docs/query/aggregation
  4. [2]: https://ebean.io/docs/query/select
  5. <details>
  6. <summary>英文:</summary>
  7. 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:
  8. .select(&quot;cluster_leader, MAX(cluster_value)&quot;)
  9. Check out these links:
  10. [Ebean aggregation][1] and [Ebean select][2]
  11. [1]: https://ebean.io/docs/query/aggregation
  12. [2]: https://ebean.io/docs/query/select
  13. </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:

确定