aspose file tools*
The moose likes Spring and the fly likes Model in Spring MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Model in Spring MVC" Watch "Model in Spring MVC" New topic
Forums: Spring OO, Patterns, UML and Refactoring
Author

Model in Spring MVC

kuldeep sidhu
Greenhorn

Joined: Jan 07, 2014
Posts: 21
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

Joined: Jul 04, 2006
Posts: 235
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
Bartender

Joined: Jan 17, 2008
Posts: 2448
    
  28

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
Bartender

Joined: Jan 17, 2008
Posts: 2448
    
  28

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Model in Spring MVC