如何解决Spring Data JPA存储库应该进入哪个软件层?
在通读this和'Repository vs Dao'之后,我对Spring Data JPA存储库的位置感到困惑。 在我的实现中,Spring Data JPA Repository中的此类存储库接口具有与数据库的隐藏技术连接。因此,它们不应该是DAO。参考资料告诉我,存储库中可能存在一些业务逻辑代码段。但是实现这种JpaRepository的存储库提供了非常简单的CRUD操作,而无需进行进一步的逻辑处理。以下代码段是通过一些业务逻辑判断从数据库中检索帐户的基本实现。所以这是我的问题。 AccountUtil类在软件层应该放在哪里? 应该在持久层还是业务层?
@Component
public class AccountUtil{
private AccountRepository repo;
@Autowired
public AccountUtil(AccountRepository repo){
this.repo = repo;
}
public Account getAccount(long id) throws AccountException{
Optional<Account> entity = repo.findById(id);
if(entity.isPresent()){
return entity.get();
} else {
throw new AccountException();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。