问题描述
每个服务应该呼叫一个DAO,例如CustomerService-> CustomerDAO,或者我们可以使用dataService可以调用CustomerDAo和ProjectDAO作为示例
Should each service call one DAO e.g. CustomerService->CustomerDAO or we can use dataService can call CustomerDAo and ProjectDAO as example
推荐答案
通常,DAO尽可能轻,并且仅存在于提供与DB的连接,有时可以使用抽象的不同的DB后端。
Generally the DAO is as light as possible and exists solely to provide a connection to the DB, sometimes abstracted so different DB back-ends can be used.
服务层用于提供逻辑来处理发送到DAO和客户端的数据。很多时候,这两个部分将被捆绑到一个模块中,偶尔也会被编入相同的代码中,但您仍然会将它们视为不同的逻辑实体。
The service layer is there to provide logic to operate on the data sent to and from the DAO and the client. Very often these 2 pieces will be bundled together into the same module, and occasionally into the same code, but you'll still see them as distinct logical entities.
当你说每个服务应该调用一个DAO,例如CustomerService-> CustomerDAO,或者我们可以使用dataService调用CustomerDAo和ProjectDAO作为示例
所以这里取决于DataService是否需要数据从CustomerDAo例如客户列表中,您应该直接在DataService中使用CustomerDAO,但是如果您需要某种计算,或者您的客户数据中存在CustomerService(基本上是在Dao相应服务上实现的这类事情),那么您去顾客服务。
So here depends on the requirement if DataService just need data from CustomerDAo e.g list of customers then you should directly use CustomerDAO in DataService, But if you need the some kind of calculation or else in your customers data and it is present on CustomerService(basically this kind of things implemented on Dao corresponding Service) then you go for CustomerService.
这篇关于Spring MVC Service DAO架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!