开发者

Spring MVC what is service component?

Could anyone please give some examples of possible service. I am going through t开发者_开发知识库he book, but cannot understand what can the service do? It provides processed data for modelAndView to controller, but what it looks like is it java bean connecting and retrieving results from database, what can it be?


A service component is where all your DAOs come together and have the business logic. You can think of it this way.

  • DAO - should only load data from db. Nothing more.
  • Services - can use daos to load multiple objects and do some kind of business logic
  • controllers - use services to load objects. They should have nothing more than simple logic because complicated logics should really belong in the service. Reason for this is in the future when you want to reuse this logic, you can do so if its a in service but not if its in the controller.

Example:

  • BookDAO - Loads the book
  • BookService - loads the books for a person that is logged in

Finally, I'd like to quote the grails doc for a clean concise quote.

As well as the Web layer, Grails defines the notion of a service layer. The Grails team discourages the embedding of core application logic inside controllers, as it does not promote re-use and a clean separation of concerns.


An example of an Service could be an Email Service in an Business Application (not in an Email-Client). This Service offer other Components the functionality (service) to send emails to notify users about stuff.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜