问题描述
Id想知道是否有一种方法可以完成 Stream API groupingBy Collector 之类的操作。我知道如何选择一个列(该问题被标记为重复列,但我不相信它是)我想进行分组(类似java Stream API的groupingBy收集器)而不是分组通过。 假设您有一个表(一个表),例如:
+---------------------+
+ myTable +
+----------+----------+
+ column_A | column_B +
+----------+----------+
+ 1 | 1 +
+ 1 | 2 +
+ 1 | 3 +
+ 2 | 1 +
+----------+----------+
我想拥有类似的东西
@Entity
@Table("MyTable")
public class MyEntity {
@Column("column_A")
private int a;
@Column("column_B") ?
private List<Integer> b; //normanly this wuould just be int b,butI want a list of all b's that have the same a
}
像回购这样的
public interface MyCrudRepo extends CrudRepository<MyEntity,Integer>{
List<MyEntity> findByA();
}
或
public interface MyCrudRepo extends CrudRepository<MyEntity,Integer>{
@Query("SELECT m.a,m.b FROM MyEntity m")
List<MyEntity> customFind();
}
这不一定是最后的样子,任何类似的工作都可以。我已经研究了预测,但是所有示例都使用2个不同的表。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)