[英]SpringBoot Hibernate. Unable to GET findAll and findById in Postman, Swager, api link for OneToMany, ManyToOne relationship
I'm unable to get response in Postman.我无法在 Postman 中得到响应。 It becomes an infinite loop I think.
我认为它变成了一个无限循环。 The models are: dish, category.
模型有:菜、类。 One category had multiple dishes.
一类有多种菜肴。
Before add Dish (id, category), it behave normal like this在添加 Dish (id, category) 之前,它的行为正常是这样的
Here is the Dish and Category model
这是菜和类别 model
Here is one of the Controller
这是 Controller 之一
The post dish working great, but the search is not.
后菜效果很好,但搜索却不行。 Anyone know how to solve it?
有谁知道如何解决它? (The db I use is Postgres)
(我使用的数据库是 Postgres)
Edit: I solved it.编辑:我解决了。 Using @JsonBackReference and @JsonManageReference
使用 @JsonBackReference 和 @JsonManageReference
Your Dish & Category are related entities.您的菜肴和类别是相关实体。
Try having @JsonIgnore annotation in your Dish class for Category field or the other way around.尝试在您的 Dish class 中为 Category 字段添加 @JsonIgnore注释,反之亦然。
Also, always use a DTO instead of returning the actual DB object in the Rest-call.此外,始终使用 DTO 而不是在 Rest-call 中返回实际的 DB object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.