Reputation: 24667
Can anyone describe when and why you might want to use Spring MVC ModelAndView instead of just returning a String for the view name and using a ModelMap.
I know one method is older than the other, but I don't know why one method might be better than the other?
Thanks
Upvotes: 2
Views: 1322
Reputation: 11
One more advantage of using ModelAndView is that it tell's the Spring container explicitly that you want to send a View and not a string in case if you are using @ResponseBody in your controller say for AJAX calls, this way if there is an error in your jsp, with ModelAndView you will get an exception whereas in the String version the String will be returned as it is to the view page without throwing any exception......
Upvotes: 1
Reputation: 24667
I think other than one style being newer than the other there is no one better way.
The String view name + ModelMap is probably more familiar to developers coming from Struts though.
Upvotes: 1