ModelAndView和ModelMap有什么区别? [英] What's the difference between ModelAndView and ModelMap?

查看:114
本文介绍了ModelAndView和ModelMap有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ModelMap 只是春天3中的新名称 ModelAndView

Is ModelMap just the new name in Spring 3 for a ModelAndView?

Spring 3中的功能是否有变化?

Does the functionality change in Spring 3?

使用 ModelMap 在Spring 3应用中考虑此代码c $ c>:

Consider this code in a Spring 3 app using a ModelMap:

 @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中使用它?

I would like to know what the equivalent use here of ModelAndView would be in an older Spring app? Would it just require a name change from ModelMap to ModelAndView to get this working in Spring 2.5?

推荐答案

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

ModelAndView, as its name suggests, contains the model, and the name of the view. ModelMap, in contract, only contains information about the model.

您的示例将被写入(在旧中Springas

Your example would have been written (in "old" Spring) as

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

这篇关于ModelAndView和ModelMap有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆