Difference between org/springframework/web/servlet/ModelAndView class and org/springframework/web/portlet/ModelAndView [duplicate]

两盒软妹~` 提交于 2019-12-12 02:40:45

问题


I have just answered the below question which revolves around this posted question.

spring mvc InternalResourceViewResolver doesnt get prefix

Can someone out there tell the difference between the classes

org/springframework/web/servlet/ModelAndView and org/springframework/web/portlet/ModelAndView

I see almost similar API docs for both

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/ModelAndView.html

and

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/portlet/ModelAndView.html

where both have the constructor

ModelAndView(String viewName)
Convenient constructor when there is no model data to expose.

and yet the latter doesn't work in resolving the view?


回答1:


Ignoring that these two are meant for two completely different environments, the difference is that org.springframework.web.servlet.ModelAndView is a supported handler method return type:

  • A ModelAndView object, with the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.

That means that Spring has a HandlerMethodReturnValueHandler implementation (ModelAndViewMethodReturnValueHandler) that will receive the return value of type ModelAndView and process it.

It does not have such a implementation for org.springframework.web.portlet.ModelAndView registered by default.

More:

  • Spring MVC Neither BindingResult nor plain target
  • How does HandlerMethodReturnValueHandler work?


来源:https://stackoverflow.com/questions/31299611/difference-between-org-springframework-web-servlet-modelandview-class-and-org-sp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!