1 回答

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
我將我的 DAO (DataAccessObjects) 稱(chēng)為“存儲(chǔ)庫(kù)”。
Spring Data JPA 也在這樣做。
所以我會(huì)創(chuàng)建一個(gè) UserRepository 和一個(gè) PaymentRepository。
存儲(chǔ)庫(kù)可以被其他存儲(chǔ)庫(kù)或服務(wù)調(diào)用。
存儲(chǔ)庫(kù)永遠(yuǎn)不應(yīng)調(diào)用服務(wù)。
UI -> 服務(wù) -> 存儲(chǔ)庫(kù)。
您的 PaymentRepository 可能會(huì)返回這樣的實(shí)體
public class PaymentEntity{
private long id;
private DateTime dateTime;
private UserEntity user;
}
您的 UserRepository 可以返回這樣的實(shí)體
public class UserEntity{
private long id;
private DateTime lastLogin;
private List<PaymentEntity> payments;
}
您的存儲(chǔ)庫(kù)可能如下所示。
public interface PaymentRepository{
PaymentEntity getPaymentById(long id);
List<PaymentEntity> getAllPayments();
}
public interface UserRepository{
UserEntity getUserById(long id);
List<UserEntity> getAllUsers();
}
因此,您的 PaymentRepository 將調(diào)用 UserRepository 以獲取用戶(hù)進(jìn)行付款。
并且您的 UserRepository 將調(diào)用 PaymentRepository 以獲取所有用戶(hù)付款
我希望我能幫助你
添加回答
舉報(bào)