1 回答

TA贡献1874条经验 获得超12个赞
我将我的 DAO (DataAccessObjects) 称为“存储库”。
Spring Data JPA 也在这样做。
所以我会创建一个 UserRepository 和一个 PaymentRepository。
存储库可以被其他存储库或服务调用。
存储库永远不应调用服务。
UI -> 服务 -> 存储库。
您的 PaymentRepository 可能会返回这样的实体
public class PaymentEntity{
private long id;
private DateTime dateTime;
private UserEntity user;
}
您的 UserRepository 可以返回这样的实体
public class UserEntity{
private long id;
private DateTime lastLogin;
private List<PaymentEntity> payments;
}
您的存储库可能如下所示。
public interface PaymentRepository{
PaymentEntity getPaymentById(long id);
List<PaymentEntity> getAllPayments();
}
public interface UserRepository{
UserEntity getUserById(long id);
List<UserEntity> getAllUsers();
}
因此,您的 PaymentRepository 将调用 UserRepository 以获取用户进行付款。
并且您的 UserRepository 将调用 PaymentRepository 以获取所有用户付款
我希望我能帮助你
添加回答
举报