'modelandview'에 해당되는 글 1건

  1. 2014.10.14 ModelAndView Class
2014. 10. 14. 06:43

(번역)

Spring MVC framework에서 ModelAndView class Model class View class 모두를 소유하는 클래스입니다. 두 클래스를 모두 소유하지만 이 두 클래스는 완전히 별개입니다. ModelAndView class단지 Controller Model객체와 View객체를 단 하나의 값으로 리턴하는 것이 가능하게 해줍니다. 그리고 이 클래스는 handler DispatcherServlet class에 의해 리턴됩니다. View class form ViewResolver객체를 이용해서 String view name으로 처리합니다. 다른 방법으로는 View객체로 직접 처리됩니다. Model클래스는 Map인데 이 Map name에 의해 키값화된 복수 객체의 사용이 가능하게 합니다


(부연설명)

원래는 View에 대한 리턴을 ModelAndView 객체로 해야하지만 View객체만 리턴해도 됩니다. Forward ViewInternalResourceView객체를 사용합니다. 그래서 우리가 직접InternalResourceView객체를 넘기면 그냥 그 View를 이용합니다. 하지만 이게 너무 귀찮으니까 SpringMVC는 우리에게 편리한 방법을 제공합니다. 우리가 단지 JSP의 경로를 쓰면 알아서 InternalResourceView를 자동으로 만들어서 작동해줍니다. WEB-INF/view/XXX.jsp라는 접미,접두사가 항상 똑같고 길기 때문에 우리가 String으로 넘길때 InternalResourceViewResolver가 있어서 그게 편리하게 작동해줍니다. , 우리는 String을 그냥 JSP의 이름만 넘기면 알아서 접두(prefix),접미사(suffix)를 만들어서 InternalResourceView를 생성해줍니다. 그런데 더 편리하게 하기 위해서 Spring MVC는 심지어 우리가 리턴하지 않으면 알아서 해당주소(index.html)에서 .html를 제외한 이름의(index)jsp를 알아서 찾습니다.(RequestMapping)


(원문)

외부링크 : java.lang.Object

org.springframework.web.servlet.ModelAndView

public class ModelAndView

extends Object


Holder for both Model and View in the web MVC framework. Note that these are entirely distinct. This class merely holds both to make it possible for a controller to return both model and view in a single return value.Represents a model and view returned by a handler, to be resolved by a DispatcherServlet. The view can take the form of a String view name which will need to be resolved by a ViewResolver object; alternatively a View object can be specified directly. The model is a Map, allowing the use of multiple objects keyed by name.

Author : Rod Johnson, Juergen Hoeller, Rob Harrop



크리에이티브 커먼즈 라이선스

 


Posted by 루피아빠