我需要将 2 个实体对象合并为 1 个模型对象,该模型对象将用于将数据返回到调用 api 方法。这种情况有通用的模式或解决方案吗?
@Entity
public class Entity1{
@Column
private String value1;
@Column
private String value2;
}
@Entity
public class Entity2{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "value1")
private Entity1 entity1;
@Column
private String value3;
}
最佳答案
对我来说,您应该使用 Facade 或 Business Delegator,它应该像两者的适配器一样返回对象。
关于java - Spring : combine 2 entities into model object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47208860/