POJO(普通Java对象)和DTO(数据传输对象)有什么区别?

发布于 2024-08-05 14:14:48 字数 31 浏览 2 评论 0原文

我找不到它们之间的区别。有谁知道如何区分它们吗?

I cannot find difference between them. Does anyone know how to differentiate them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

情魔剑神 2024-08-12 14:14:48

POJO 或“普通旧 Java 对象”是用于描述“普通”Java 对象的名称,而不是 EJB(最初)或任何依赖于其他技术的“重型”对象。

DTO 或“数据传输对象”是一个用于......嗯......传输数据的对象,通常在“业务”类和持久层之间。它通常是一个无行为的类,非常类似于 C 风格的结构。它们是一个过时的概念。

POJO or "Plain Old Java Object" is a name used to describe "ordinary" Java objects, as opposed to EJBs (originally) or anything considered "heavy" with dependencies on other technologies.

DTO or "Data Transfer Object" is an object for... well... transferring data, usually between your "business" classes and persistence layer. It typically is a behavior-less class much like a C-style struct. They are an outdated concept.

故笙诉离歌 2024-08-12 14:14:48

POJO 只是一个简单的 Java 对象,使用缩写词是为了强调它确实没什么特别的。

DTO 是一种数据传输对象,用于封装通过层或子系统之间的连接传输的数据。请参阅维基百科文章,它也是一个核心 J2EE 模式 (http://www. oracle.com/technetwork/java/transferobject-139757.html)。

http://en.wikipedia.org/wiki/Data_transfer_object

A POJO is just a simple Java object, the acronym is used to emphasize that it really is nothing special.

A DTO is a Data Transfer Object which is used to encapsulate data that is transferred over a connection between layers or subsystems. See the wikipedia article, it's also a Core J2EE pattern (http://www.oracle.com/technetwork/java/transferobject-139757.html).

http://en.wikipedia.org/wiki/Data_transfer_object

如果没有你 2024-08-12 14:14:48

所有 DTO 都是 POJO,但并非所有 POJO 都是 DTO。非 DTO 的 POJO 示例是包含状态和行为(业务逻辑)的业务类。

All DTOs are POJOs, but not all POJOs are DTOs. An example of POJO that is not a DTO is a business class that contains state and behavior (business logic).

痴骨ら 2024-08-12 14:14:48

DTO(数据传输对象):是一种核心 J2EE 设计模式,用于在系统内传输数据。DTO 模式

POJO(普通旧 Java 对象):它只是人们用来暗示它是一个简单的 java 对象的缩写词(如今,它被大量注释为做一些有意义的完整工作)。

DTO 模式

J2EE 模式目录

DTO (Data transfer object) : Is a Core J2EE design pattern used for transferring data within the system.DTO Pattern

POJO (Plain Old Java Object) : It is just an acronym people use for suggesting that is a simple java object (which nowadays is heavily annotated for doing some meaning full work).

DTO Pattern

J2EE Pattern Catalog

身边 2024-08-12 14:14:48

DTO是pojo,但pojo不是dto,因为pojo可以有更多行为而DTO则基本没有行为

Oracle文档有明确的描述。

DTO is pojo, but pojo is not dto, because pojo can have more behavior but DTO just basically no behavior

Oracle document has clear description.

流年已逝 2024-08-12 14:14:48

POJO 可以有行为。 《POJOs in Action》一书详细介绍了如何使用 POJOS 进行应用程序开发。
DTO 是帮助将数据从一层传输到另一层的数据容器。 DTO 不应包含任何行为。

A POJO can have behavior. The book POJOs in Action details use of POJOS for application development.
DTOs are data containers that help transfer data from one layer to another. DTOs aren't supposed to contain any behavior.

伴我心暖 2024-08-12 14:14:48

DTO's wiki的这句话我可以理解POJO和DTO之间的区别:

DTO 是简单的对象,不应包含任何业务逻辑,但可能包含用于通过线路传输数据的序列化和反序列化机制。

此外,Martin Fowler 的 企业应用程序架构模式目录 中对 DTO 进行了完美的可视化和详细描述

I could understand the difference between POJO and DTO from this sentence of DTO's wiki:

DTOs are simple objects that should not contain any business logic but may contain serialization and deserialization mechanisms for transferring data over the wire.

Also, DTO is perfectly visualized and described in detail in Martin Fowler's Catalog of Patterns of Enterprise Application Architecture

你的往事 2024-08-12 14:14:48

POJO = 普通旧 Java 对象

DTO = 数据传输对象

- 编辑

好吧,这是假设您不知道缩写词的含义。 Pojo 只是一个不受任何继承链影响的对象。 DTO 存在于您的数据模型中,因此可能遵循将其与给定实体关联的严格链。

POJO = Plain Old Java Object

DTO = Data Transfer Object

-- Edit

Well, this is assuming you don't know what the acronyms mean. A Pojo is just an object that is free from any sort of inheritance chain. A DTO exists in your data model, so probably follows a strict chain relating it to a given entity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文