简体   繁体   English

我们可以有相互依赖的模型吗?

[英]Can we have models who depends on each other?

class Parent {
    long id;
    List<Child> children;   
}

class Child {
    long id;
    Parent parent;
}

GET /parents/1, here have to show children of Parent 1 GET /parents/1,这里必须显示 Parent 1 的孩子

GET /children/101 here have to show Parent of Child 101 GET /children/101 这里必须显示孩子 101 的父母

I actually didnt like above circular dependency design, but I am not understanding how to fix above scenario.我实际上不喜欢上述循环依赖设计,但我不明白如何解决上述情况。 Need some help to fix above design issue.需要一些帮助来解决上述设计问题。

And also iam not sure whether can we have DTOs who depends on each other?而且我不确定我们是否可以拥有相互依赖的 DTO? Is this correct design?这是正确的设计吗?

Yes.是的。 You can have models that depend on each other.您可以拥有相互依赖的模型。 This is widely used in hibernate.这在 hibernate 中被广泛使用。 Your example is like one to many mapping.您的示例就像一对多映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 牙签绑定彼此依赖的模块 - Toothpick bind modules that depends on each other 更改EditText字段的值相互依赖 - Values of EditText fields are changed depends on each other Spring Boot:我们可以为每个请求设置单独的线程池吗? - Spring Boot: Can we have seperate thread pool for each request? 我们可以建立2个APK,一个用于调试,另一个用于测试 - Can we have built 2 APK one for debug and other for test 我们可以在其他地图中使用嵌套地图作为键吗? - can we have a nested map as key within other map? 使用可以在GAE数据存储中相互发送消息的用户对系统进行建模 - Modeling a system with users who can send messages to each other in GAE datastore Java构建相互依赖的事件链 - Java building chain of events which depends on each other 除了Oracle以外,还有谁实现了JVM规范? 除了Oracle,还有其他JRE / JDK吗? - who are other than oracle who have implemented JVM spec ? Is there other JRE/JDK than from Oracle? 如何组合相互依赖的 Observables 并从每个对象中获取一个包含值的对象? - How to combine Observables which depends each other and get an object that contain a value from each? 我们可以拥有一个集合数组吗? - Can we have an Array of a collection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM