gpt4 book ai didi

java - Spring 数据 JPA : find nested object

转载 作者:行者123 更新时间:2023-11-30 07:03:11 24 4
gpt4 key购买 nike

我有一个 LOCATION 实体,它包含 COUNTRY、STATE 和 CITY。我有一个 LocationRepository 接口(interface)定义为:

public interface SpringDataLocationRepository extends LocationRepository,
Repository<Location, Integer> {
}

我想按国家/地区查找所有州。我可以按照方法名称标准来查询 LOCATION 实体的所有内容。如果我想要 List,是否需要创建 StateRepository 接口(interface)并在其中查询有关 STATE 的所有信息?如果我只能从 LocationRepository 获取它,该方法是什么样的?我假设它看起来像下面这样(当然它不起作用)。

列表 findStateByCountryCountryId(Integer id) 抛出 DataAccessException;

最佳答案

下面的方法应该有效:

List<Location> findByCountryId(Integer id)

然后您可以从列表中的 Location 对象获取状态。

PS:当然,这不是我测试/执行的。

关于java - Spring 数据 JPA : find nested object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28571688/

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