I'm building a Spring MVC application and just wondering what the convention is concerning modeling and view.
Is it better to return a ModelAndView or just return a view name as a string?
Example
public ModelAndView showInformation(){
ModelAndView myMV= new ModelAndView("display-information");
myMV.addObject("info",myObject);
return myMV;
}
OR
public String showInformation(Model theModel){
theModel.addAttribute("info",myObject);
return "display-information";
}
In my opinion, using ModelAndView makes your intentions much clearer, but it involves more setting up compared to simply returning a string.