gpt4 book ai didi

java - 如何忽略 GET 请求的 @OneToMany 关系?

转载 作者:行者123 更新时间:2023-12-01 19:30:57 25 4
gpt4 key购买 nike

我有一个名为 Restaurant 的实体,它有另一个类的对象集:

@Entity
@Table(name = "restaurants")
public class Restaurant extends AbstractNamedEntity implements Serializable {

@OneToMany(fetch = FetchType.LAZY, mappedBy = "restaurant")
private Set<Meal> meals = Collections.emptySet();
//getters, setters and other variables
}

类“Meal”与“Restaurant”有@ManyToOne关系。

我有 Spring JPA 存储库:

@Repository
public interface RestaurantRepository extends CrudRepository<Restaurant, Integer> {
}

当我使用 findById() 方法时 - 我正在一家餐厅提供餐点 enter image description here

我需要找一家不提供任何餐点的餐厅。不得从存储库中获取集合 - 应将其忽略我该怎么做?

最佳答案

您可以在属性上添加 @JsonIgnore 注释,或创建一个仅包含模型所需属性的 DTO。

关于java - 如何忽略 GET 请求的 @OneToMany 关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59777807/

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