在Spring Data JPA Repository中,我需要指定多个执行相同操作的方法(例如:findAll),但是需要指定不同的@EntityGraph注释(目的是在不同的服务中使用优化的方法)。
@Repository
public interface UserRepository extends JpaSpecificationExecutor<User>, JpaRepository<User, Long> {
@EntityGraph(attributePaths = { "roles" })
findAll[withRoles](Specification sp);
@EntityGraph(attributePaths = { "groups" })
findAll[withGroups](Specification sp);
etc...
}
在Java中,我们不能使用相同的方法签名多次,那么如何管理它呢?
是否可以不使用JPQL实现?
谢谢,
Gabriele
EntityGraph
作为参数使用:https://dev59.com/V6zka4cB1Zd3GeqP6U2N - Olivier Depriester