Spring MVC controller

Take a look at the following controller:

    @Controller 
public class BasicModelViewController {
@RequestMapping(value = "/welcome-model-view")
public ModelAndView welcome(ModelMap model) {
model.put("name", "XYZ");
return new ModelAndView("welcome-model-view", model);
}
}

A few important things to note are as follows:

  • @RequestMapping(value = "/welcome-model-view"): The URI mapped is /welcome-model-view.
  • public ModelAndView welcome(ModelMap model): Note that the return value is no longer a String. It is ModelAndView.
  • return new ModelAndView("welcome-model-view", model): Create a ModelAndView object with the appropriate view name and model.