我想获得分支对象,其中 leaf (使用它的ID)属于
获取分支的正确方法是什么,因为我只有 leaf ID?我想循环遍历数据库中的所有分支,并获取包含看起来不好的叶ID的那个
static
答案 0 :(得分:2)
尝试这样的事情:
public interface BranchRepository extends JpaRepository<Branch, Long> {
@Query("select b from Branch b join b.leaves l where l.id = ?1")
List<Branch> getByLeafId(Long leafId);
}
@Service
public class BranchService {
private final BranchRepository branchRepository;
@Autowired
public BranchService(BranchRepository branchRepository) {
branchRepository = branchRepository;
}
public List<Branch> getByLeafId(Long leafId){
return branchRepository.getByLeafId(Long leafId);
}
}