您应该在视图层中公开 JPA 吗?
在 MVC 模型中,您应该在控制/视图层中公开 JPA 对象,还是应该使用另一个对象代理这些对象。我并不是建议授予对模型层之外的 DAO 的访问权限,而只建议授予对 JPA 对象的访问权限。我懂了... 使用 JPA 对象的好处是您不必在 JPA 和代理对象之间来回复制所有数据。我想缺点很简单,它可能不完全适合 MVC 模型以允许模型层对象在视图层中可见。
In an MVC model, should you expose your JPA objects in the control/view layers or should you proxy those objects with another object. I'm not suggesting giving access to the DAO outside of the model layer, just the JPA objects. I see...
The benefit of using the JPA objects is that you don't have to needlessly copy all the data back and forth between the JPA and the proxy object. I guess the con is simply that it may not perfectly fit the MVC model to allow model layer objects visibily in the view layer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说这没关系,除非对保持层纯度有明显的好处,或者将模型对象传递到视图层会造成损害。
我不喜欢并行对象层次结构的想法 - 创建 DTO 需要做大量工作,只是为了在层之间传输数据以保持对象纯度。
我一直认为这是由 EJB 1.0 实体 bean 之间的“闲聊”通信引起的,激发了这种反模式。既然我们已经有了 EJB 3.0,为什么还要让它保持活力呢?
I would say it's okay, unless there's a clear benefit to maintaining layer purity, or harm caused by passing model objects to the view layer.
I don't like the idea of parallel object hierarchies - it's a lot of work to create DTOs just for the sake of ferry data between layers for the sake of object purity.
I always thought it was caused by "chatty" communication between EJB 1.0 entity beans that inspired this anti-pattern. Why keep it alive now that we have EJB 3.0?