I have following controller which is serving different requests. I am wondering if the way that I create ModelAndView is correct? I am creating one object in each method. Is there any better approach?
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showNames() {
...
ModelAndView model = new ModelAndView("names");
model.addObject ....
return model;
}
@RequestMapping(value = "/name/{name}", method = RequestMethod.GET)
public ModelAndView showNameDetails(@PathVariable String name) {
...
ModelAndView model = new ModelAndView("name");
model.addObject ...
return model;
}
@RequestMapping(value = "/name/{name}/{item}", method = RequestMethod.GET)
public ModelAndView showItemsOfName(@PathVariable String name,
@PathVariable String item) {
...
ModelAndView model = new ModelAndView("item");
model.addObject ....
return model;
}