Spring MVC controller

Let's create a simple Controller. Consider the following example controller:

    @Controller 
public class BasicModelMapController {
@RequestMapping(value = "/welcome-model-map")
public String welcome(ModelMap model) {
model.put("name", "XYZ");
return "welcome-model-map";
}
}

A few important things to note are as follows:

  • @RequestMapping(value = "/welcome-model-map"): The URI mapped is /welcome-model-map.
  • public String welcome(ModelMap model): The new parameter added is ModelMap model. Spring MVC will instantiate a model and make it available for this method. The attributes put into the model will be available for use in the view.
  • model.put("name", "XYZ"): This adds an attribute with the name name and XYZ value to the model.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset