我有这种情况:
它即将与
Spring Data
合作并使用 @Entity
的一组特定字段这两个建议对我来说完全有效:
DTO projections
Projection interfaces
更多,在
spring-data-examples
两者一起出现(我知道是为了示例):因此:
备注 在 Class-based Projections (DTOs)部分内容如下:
Another way of defining projections is by using value type DTOs (Data Transfer Objects) that hold properties for the fields that are supposed to be retrieved. These DTO types can be used in exactly the same way projection interfaces are used, except that no proxying happens and no nested projections can be applied.
似乎优点是:
except that no proxying happens
和 no nested projections can be applied
最佳答案
DTO 方法
临
骗局
DTO 的代码)。
预测
临
根据客户的需要,实体对象中属性的不同子集。
骗局
如果您需要嵌套或动态投影,您可能需要投影方法而不是 DTO 方法。
引用 official Spring doc详情。
关于jpa - Spring 数据: when use Projection interfaces and DTO projections?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50176316/