java - Should the service in an MVC app return entities or list of entities -


i've mvc application spring , hibernate

i've each controller calling service layer call dao

controller > service > dao 

should service return entities?

i trying move logic controller service. @ moment logic in controller

autenticate  retrieve user information (service call)  retrieve appointments (other service call)  create status response in xml  return appointemnts 

as can see if move logic in service need service call return xml instead of user or list of appointemts.

is right way or should keep logic in controller , return service entities?

as far understand it, think immaterial you. must remember

  • to keep service layer clean of data access implementations (for example: import java.sql.whatever bad idea inside service layer)
  • the service layer ideal place put declarative transaction management in. idea write transactional service layer methods, , under that, have totally naive dao layer have connections injected, errors managed outside, no commits, no rollbacks...

your idea of moving logic out of controller layer sound. concern xml legitimate, but, whatever service layer returns, remember format matter presentation layer. service layer (and ideally controller too) should unaware of format rendered user. way have proper service layer reusable across many presentation layers devise application.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -