Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API in Spring Boot Repository vs DAO

I'm trying to design an rest API in spring boot and what to ask about a few design decisions. I am completely confused by the whole difference between DAO vs Repository pattern/design. After hours of reading I still don't really understand the difference between the two or which one is preferred standard for designing API's that make backend connections.

Here's a simply UML diagram to highlight the high level view of the api: enter image description here

This is how I understand a good architecture of an API. But then I came across this article using repository pattern instead of dao with a specification design. I don't understand why a dao interface can't just have a query function? Does that break the idea of what a DAO is or something?

My question is: what's the best standard to use in today's day in developing an API in Spring Boot and Java 8

like image 733
Richard Avatar asked Apr 27 '17 16:04

Richard


1 Answers

If I understood correctly your question, the whole point of using Spring Service/Repository is to separate the business logic from the Controller to the Service class, and the only thing the Repository will do is DB operations, and you will inject it in your Service. There is no difference between DAO (assuming your DAO is a bunch of code using JPA) and Repository, but with Spring Repository you can use Query Methods, which is awesome!

Any suggestion, feel free!

like image 76
Mateus Luiz Avatar answered Oct 22 '22 09:10

Mateus Luiz