Dilis
Dilis

Reputation: 267

what are the Spring MVC Corresponding Components for Model, View, and Controller?

I'm new to spring 3. I studied several tutorials about springmvc, but I can't separately identify what are the corresponding components for model view and controller? Like in struts2

Upvotes: 3

Views: 291

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298838

In Spring MVC, a Controller is usually a Plain java class annotated with @Controller, a View is anything that implements org.springframework.web.servlet.View and the model is usually a ModelMap, a specialized Map implementation.

In a standard setup, a controller method usually returns either a String or a business object. If it returns a String, that is interpreted as a path to the view name (JSP, Freemarker etc.). If it is a business object and the method is annotated with @ResponseBody, then content negotiation starts, one of the key features of Spring MVC. Depending on configurable aspects like the Accept: header, the path extension etc. Spring automatically serializes the business object to JSON, XML, PDF etc.

The whole mechanism is explained in the Spring Reference under

Spring MVC: Implementing Controllers

Upvotes: 2

Related Questions