3

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:

Layers:

  • 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.

  • 1
    I'm not sure if Spring proposes any specific layered architecture or workflow. Layers and workflows vary from project to project regardless Spring. For example, I have implemented applications with 2, 3 and 4 different layers. Sometimes we use DTO (if needed) others we don't. Models often are anemic but nothing stops you from implementing DDD, It depends entirely on your needs, not on the framework. I suggest taking a look at Springs guides as a starting point. Each guide use to has a demo project in Github – Laiv Sep 1 '17 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.