您应该问自己为什么需要某种模式。就企业模式而言,没有最佳实践之类的东西。正如@TechExchange 所建议的那样,将数据库中的数据结构包装在一个对象中以保持您的接口紧凑和稳定,这是一个有效的关注点。但正如@Tom Anderson 指出的那样,这应该被称为值对象,而不是 DTO。
请记住,对 DTO 模式的需求有一些历史原因(参见此处),主要是在 EJB-3 之前的世界中。这些可能不再适用。
DTOs can help separating higher layers from accessing the data layer directly. In a simple CRUD application this can however add too much indirection and thus unnecessary duplication and complexity, thus more maintainance. You often end up having DTOs that look very similar to the entities that may not leave the data access layer.
DTOs can be especially helpful in distributed systems where they lead to more coarse grained interfaces and reduce network traffic.