0

currently I'm learning the SpringMVC + Hibernate. And I'm confused while implementing a simple user account manager application.

In my case:

  1. the user account should be read from the database;
  2. the password should be compared before any modification;
  3. the user account information should be modified according to the frontend form;
  4. the user account with new information should be save back to the database;

My questions are:

  1. Should this whole process be implemented in the Service or in the Controller? And why?
  2. In many examples I read that the service methods are usually tiny and contains only one DAO call, is this a good practice? Or we do the contrast to put several DAO calls into one service methods?
xiGUAwanOU
  • 325
  • 2
  • 16

1 Answers1

1

Should this whole process be implemented in the Service or in the Controller? And why?

Business logic is done in the service layer (the M in MVC) - see the link below for explanations.

In many examples I read that the service methods are usually tiny and contains only one DAO call, is this a good practice? Or we do the contrast to put several DAO calls into one service methods?

Service methods are of the proper size for the logic they perform. If for a particular logic you need access to several DAOs, or other services for that fact, you do so. If the logic is 10 lines of code or 100 then that's the size of the method. The thing is that most examples out there use a service layer (which your application should have) but because they are just that, examples, there isn't any logic in them. For this reason most of them just delegate to some DAO, confusing people about what their purpose should be.

Read the following for details: The Purpose of a Service Layer and ASP.NET MVC 2 (it's for .NET but the principles still apply).

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61