Spring service and repository layer convention

霸气de小男生 提交于 2020-01-14 09:38:07

问题


I start working with Spring and have some confusions about its conventions.

  1. Is it fine to put Repositories in Controller?
  2. In a Service class, If I want to reuse code could I inject other Services and other Reposities?
  3. is it the best practice to name Service And Repository class is based on Entity name i.e: User -> UserRepository->UserService?

回答1:


  1. No, don't use Repositories in the Controller. Only in the Services. And don't use Entities in your Controller. Create Dto (Data Transfer Objects) Object from the Entities and work with this in your frontend

    1. Yes you can use other services and respositories in your service class

    2. Yes it is. Name the interfache UserService and the implementation UserServiceImpl




回答2:


Check also answer:

It explains the Persistence Bussines and Presentation layers

https://stackoverflow.com/a/34084807/2218992



来源:https://stackoverflow.com/questions/34058238/spring-service-and-repository-layer-convention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!