The Controller method to show the form

Let's start with creating a simple controller with a logger:

    @Controller 
public class UserController {
private Log logger = LogFactory.getLog
(UserController.class);
}

Let's add the following method to the controller:

    @RequestMapping(value = "/create-user",  
method = RequestMethod.GET)
public String showCreateUserPage(ModelMap model) {
model.addAttribute("user", new User());
return "user";
}

Important things to note are as follows:

  • @RequestMapping(value = "/create-user", method = RequestMethod.GET): We are mapping a /create-user URI. For the first time, we are specifying a Request method using the method attribute. This method will be invoked only for HTTP Get Requests. HTTP Get Requests are typically used to show the form. This will not be invoked for other types of HTTP requests, such as Post.
  • public String showCreateUserPage(ModelMap model): This is a typical control method.
  • model.addAttribute("user", new User()): This is used to set up the model with an empty form backing object.
..................Content has been hidden....................

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