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";
}

}

The following definitions explain the code in detail:

  • @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 incorporated into the model will be available for use in the View.
  • model.put("name", "XYZ"): This adds an attribute with the name name and the 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