While learning the Spring framework, I notice in the book Spring in Action, the author doesn\'t use ModelandView method return type in controllers. The aut
Functionality wise there is no difference, both these are equivalent:
@RequestMapping(..)
public String requestMapping1(Model model){
model.addAttribute("attr1", attr1);
return "viewName";
}
@RequestMapping(..)
public ModelAndView requestMapping2(){
ModelAndView modelAndView = new ModelAndView("viewName");
modelAndView.addObject("attr1", attr1);
return modelAndView;
}
However the preferred approach is the former and that is the reason why the author has not used the latter in the book samples.