Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Model in Spring MVC

 
kuldeep sidhu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced this question in an interview. Please clarify.
Question is as follows-
We are having some small spring web applications in which List of Employees and some other info needs to be displayed on page.
So he asked how will you achieve it.
Acc to me we can create a new class (for example EmployeeInfo) which will contain a List of Employees and some other class level variables to accommodate the extra info that need to be displayed.
After populating the EmployeeInfo class, we will add it to Model object. And in jsp we can easily get the details.

The question is what is model in this Employee class or EmployeeInfo class that we added to Model object.?
And please clarify what Model is in MVC? Is it just to transfer data from Controller to View?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Model is anything that holds your data.
Controller takes care of handling requests and send responses.
And the response contains data to be displayed in view.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not really a Spring question, and more of a Design pattern Question. I'm putting this topic in the Patterns forum
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an MVC pattern. Model is anything that represents your data. The Controller is responsible for business logic and the view is responsible for displaying the data. Generally the model is made up of POJOs that represent the application's data.. and nothing else. In your case you will have POJOs for Employee and EmployeeInfo. If you are using JPA or any other kind of ORM for your data access, it;s not uncommon to annotate the pojos with annotations that tell the DAO how to map the POJO to the database schema.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic