0

I'm following several guides and tutorials to learn how to use Spring Boot framework, also I've red some articles about MVC and DAO design pattern, but the information is kind of ambiguous, some of the examples use the class "serviceObject" to access methods in the class "repositoryObject", others just make use the "repositoryObject" class directly, I've seen even tutorials where people creates a new interface for the object and the same time creating an implementation of JPARepository or any other Repository, so I would like to know from you guys, the experienced, how should I implement the design pattern? What's the correct form of using the framework?

By the other side some days ago I found out that Entities and DTO are not the same and that they are meant to different uses, Entities will handle the data transaction between logic layer and business layer to database, but DTO will be in charge of what information is shown in the frontend, that's what I understand but I have my doubts, and if it's that way how should be implemented this?

So I kindly request you, can you please explain me these concepts in a way that a kid can understand (apples and a board, a student table with id, name and age maybe)?

By the way I'm doing a practice project that it's: Data JPA, Web, Thymeleaf <- (Still don't understand very well what this is for, but in the practice I will learn).

Thank you in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AjFmO
  • 395
  • 2
  • 4
  • 18

2 Answers2

0

At the level of the DAO layer. you can implement JpaRepository orCrudRepository both having the same functions. either use annotations like @ Repository but first make imports at the dependency manager level. DTO's goal is to better organize its code, avoid overloading the business layer. It allows operations on a specific object using its properties without modifying it.

Berthol Yvano
  • 306
  • 3
  • 8
0

After reading a lot and follow a lot of info, I realize that there're many things to consider before taking a decision.

When it comes to using a Service Layer between a Repository and a Controller (Best practices says that we should do it this way) you should take into consideration a few aspects:

  • Is the business logic big and complex?
  • Do you have complex query consults to the database?

If the answer is NO then just don't get complicated and don't use that (by the time). Even though Best practices says that we should use that Service layer.

When it comes to DTO, there are others considerations, DTO works to serve and retrieve data to the View layer, but this data comes from the Service layer as an Entity and is converted to EntityDTO and vice-versa. Basically, DTO saves resources, improve performance, make easy to maintain in future changes in the project in the database or entities, also applies in big projects, but is good to know about this.

I will point to this post that helped me out to understand.

And this masterpiece will make you understand the importance of the correct use of DTO.

AjFmO
  • 395
  • 2
  • 4
  • 18