我正在从事一个使用JHipster生成的Spring和Java项目。我想在桌子上过滤与他人没有直接关系的东西。
我的目的几乎是在之前的一个类似问题中被问到的。
Write Spring Specification with multiple inner join & other conditions
但在我的例子中,我有两个不相关的实体:
顾问 (id : Long,FullName : string,profileRank : Enum of string )
等级 (id : Long,level : Enum of string,rate : Double )
Consultant | Rank
|
id | FullName | profileRank | id | level | rate
1 | aaaaa | 'ONE' | 1 | 'ONE' | 1
2 | bbbbbb | 'THREE' | 2 | 'TWO' | 2
3 | cccccc | 'FOUR' | 3 | 'THREE' | 3
4 | dddddd | 'THREE' | 4 | 'FOUR' | 4我想使用级别按rate筛选顾问列表
例如:找费率大于3的顾问
Expected result
id | FullName | profileRank
3 | cccccc | 'FOUR' 我在文档和许多文章中搜索过,但没有让它工作,请告诉我如何做到这一点。
发布于 2021-01-26 22:42:19
您不需要为您的情况编写规范。
list.stream(rank => rank.level).collect(toList())List<Rank>,步骤3的结果将传递给像List<Consultant> findByProfileRankIn(List<String> levelNames)这样的存储库方法。
另一种选择是加入类似于这个Joining tables without relation using JPA criteria的东西
如果你还想要一个规范,那也是可能的。Spring Data Join with Specifications
https://stackoverflow.com/questions/65910226
复制相似问题