I am new to Spring as well as layered architecture. So am a bit confused as how data flows among the different layers.
What so far I have understood is:
- Controller (which accepts requests)
- Model (simple POJO with dependencies, which depicts database table)
- DTO (expansion of Model objects i.e. flattening; without any dependencies)
- DAO (which interacts with database directly)
- Service (contains main business logic like data validation and other operations with inputs)
Data flow (interaction between layers):
Request comes from client to controller.
Controller forwards request to service class.
Service class performs appropriate operations with data, and if there are any database operations required, than service layer calls respective DAO class methods.
DAO class makes use of DTO object, to store data while performing database operations.
DTO and Model are mapped with each other with the help of ModelMapper in service class.
DTO object is returned back to controller by service class.
Controller returns DTO object to the client as a response.
Is this whole situation correct? If there are any changes, than please guide me correctly. Also I am confused that, actually where Model object is used, as we are using DTO objects only everywhere. Thank you.