When the user submits the form, the browser sends an HTTP POST request. Now let's create a method to handle this. To keep things simple, we will log the content of the form object. The complete listing of the method is as follows:
@RequestMapping(value = "/create-user", method = RequestMethod.POST) public String addTodo(User user) { logger.info("user details " + user); return "redirect:list-users"; }
A few important details are as follows:
- @RequestMapping(value = "/create-user", method = RequestMethod.POST): Since we want to handle the form submit, we use the RequestMethod.POST method.
- public String addTodo(User user): We are using the form backing object as the parameter. Spring MVC will ...