문제

I'm developing a web application with Spring MVC, Spring Data JPA and Hibernate, the data access part is taken care of by the repositories provided by Data JPA

However, I'm planning to have a generic service layer (atleast for the common operations), is it a good practise? Or is it advised to not generalise it?

도움이 되었습니까?

해결책

If your app is simple (mostly CRUD) operations then you can access your Repository classes directly.

If you have additional server-side business logic that needs to be applied to data or if you need to orchestrate multiple data access calls together then adding a Service layer would be appropriate.

다른 팁

If part of you application will consist of repeating same actions on different objects, it can make sense to have a generic abstract parent class for common operations.

You will have to decide if the gain in de-duplication of code is worth the complexity of the generic. There is no general rule ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top