5

In the repository layer I define normal data operations such as inserting, finding and so on. I am using Spring and I have the @Repository annotation above the class. Is it bad to use this class directly in the @Controller class for instance? Should all repositories always have a service layer that just delegate to the repository layer?

4

2 回答 2

2

It totally depends on your choice. In Spring Roo, you don't just skip the Repository or Service layer, but use a Rich Domain Model where you have the data access logic in the domain itself. Frameworks like Groovy on Grails use a single Repository layer. So i think its OK to use it directly in the Controller.

于 2013-04-19T11:46:27.247 回答
1

我同样问过 EJB 有什么用一个答案是这样说的:

您的 [服务层] 通常会编排业务逻辑的应用程序,但通常不会实际执行它,它通常是一个非常薄的包装器。

服务层方法可以定义作为事务的操作,因此具有注释以自动为您添加 AOP 事务支持。另请参阅相关问题的答案,其中说:

Spring 的习惯用法会建议有一个了解工作单元的服务接口和一个处理关系数据库的持久性接口。服务接口中的方法应该与您的用例密切相关。服务实现了解实现用例目标所需的所有模型和持久性包和类。

于 2013-04-19T12:37:59.290 回答