org/springframework/web/servlet/ModelAndView class 和 org/springframework/web/portlet/ModelAndView 之间的区别

Difference between org/springframework/web/servlet/ModelAndView class and org/springframework/web/portlet/ModelAndView

我刚刚回答了以下围绕此已发布问题的问题。

有人能说出 类

之间的区别吗

org/springframework/web/servlet/ModelAndVieworg/springframework/web/portlet/ModelAndView

我看到两者几乎相似的 API 文档

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

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

两者都有构造函数

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

然而后者在解析视图时不起作用?

忽略这两个是针对两个完全不同的环境,区别在于 org.springframework.web.servlet.ModelAndViewsupported 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.

这意味着 Spring 有一个 HandlerMethodReturnValueHandler implementation (ModelAndViewMethodReturnValueHandler) 将接收类型 ModelAndView 的 return 值并处理它。

它没有为 org.springframework.web.portlet.ModelAndView 默认注册的实现。

更多:

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