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

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.