ModelAndView和ModelMap有什么区别?

ModelMapModelAndView在Spring 3中的新名称吗?

function是否会在Spring 3中发生变化?

使用ModelMap在Spring 3应用程序中考虑此代码:

  @RequestMapping(value = "/order", method = RequestMethod.GET) public final String setup(final ModelMap model) { model.addAttribute(ORDER, new Order()); return "setup"; } 

我想知道ModelAndView在旧版Spring应用程序中的等效用途是什么? 是否只需要从ModelMap更改为ModelAndView以使其在Spring 2.5中运行?

顾名思义, ModelAndView包含模型视图的名称。 合同中的ModelMap仅包含有关模型的信息。

你的例子将被写成(在“旧”Spring中)

  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { return new ModelAndView("setup", ORDER, new Order()); } 

@ coder247如果我错了,有人会纠正我,但你不需要返回ModelMap。 将属性添加到ModelMap中,只需返回一个String,即View名称。

这是一篇很好的文章,解释了如何做到这一点以及更多…… http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-annotation-example/