문제

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

  • model-action class
  • view-jsp
  • controller - filterDispatcher Can anyone help me to identify these components clearly?
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top