gpt4 book ai didi

java - 我可以查询 Spring JPA @Query 来查找列表与另一个列表的任何匹配项吗?

转载 作者:行者123 更新时间:2023-12-01 08:48:55 25 4
gpt4 key购买 nike

我需要找到匹配的实体,其中父实体中有一个列表,我将传入一个 Id 列表作为参数,并且我想匹配内部列表包含任何参数 Id 的任何父实体,可以这可以在没有谓词方法的情况下完成吗?我知道以下内容不会起作用,但希望得到任何指点,已阅读 http://docs.spring.io/spring-data/jpa/docs/current/reference/html/并且这种情况不包括在内。

@Query("SELECT CASE WHERE COUNT (parent) > 0 THEN 'true' ELSE 'false' END FROM Parent parent LEFT JOIN parent.children children where :ids in children")
boolean isFound(@Param("ids") List<Long> ids;

最佳答案

如果您使用 Spring JPA,您可以执行以下操作:

@Repository
public interface ParentRepository extends CrudRepository<Parent, Long> {
Boolean existsCountByChildrenIn(List<Integer> ids);
}

关于java - 我可以查询 Spring JPA @Query 来查找列表与另一个列表的任何匹配项吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42508307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com