I\'ve seen examples where a controller returns a String (which indicates the view)
@RequestMapping(value=\"/owners/{ownerId}\", method=RequestMethod.GET)
pub
public String findOwner(@PathVariable String ownerId, Model model) {
Owner owner = ownerService.findOwner(ownerId);
model.addAttribute("owner", owner);
return "displayOwner"
}
in this method the return type is String and we adding Model as a parameter so to add a value with model we will add like
modelparam.addAttribute("obj",value);
and return to the displayowner to jsp as per view resolver
public ModelAndView helloWorld() {
ModelAndView mav = new ModelAndView();
mav.setViewName("helloWorld");
mav.addObject("message", "Hello World!");
return mav;
}
in this method the return type is ModelAndView so we will return the model and here the mav is the object of ModelAndView so here we should add like
model.addObject("object","value");
here the viewname is returned to helloworld.jsp as per the viewResolver