views:

258

answers:

1

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

Does the functionality change in Spring 3?

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";
 }

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?

+1  A: 

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

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

 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
 {
  return new ModelAndView("setup", ORDER, new Order());
 }
skaffman
About the new spring 3: If I return only ModelMap, then how is the view returned? Newbie here...
Abhijeet Kashnia
@Abhijeet: Spring will infer the view name from the request URI.
skaffman