@RequestMapping, @GetMapping and @PostMapping in Spring

@RequestMapping Originally, Spring had only @RequestMapping annotation for mapping all the incoming HTTP request URLs to the corresponding controller methods. @RequestMapping(value = "/users", method = RequestMethod.GET) public Users getUsers() { } @RequestMapping(value = "/users", method = RequestMethod.POST) public User createUser(User user) { } @RequestMapping(value = "/users/{id}", method = RequestMethod.GET) public User getUser(@PathVariable("id") String id) { …

The Spring @Controller and @RestController Annotations

In Spring Boot, the controller class is responsible for processing incoming REST API requests, preparing a model, and returning the view to be rendered as a response. The controller classes in Spring are annotated either by the @Controller or the @RestController annotation. These mark controller classes as a request handler to allow Spring to recognize …