Controller get method to handle form submit

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 ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.