How does @RequestMapping handle different types of HTTP requests?

@RequestMapping handles different HTTP methods on the same URL by accepting a method attribute that restricts which verb (GET, POST, PUT, DELETE, etc.) a given handler method responds to.

Key Points

Example

A REST controller for /items might have one method annotated @GetMapping("/items/{id}") to fetch an item and another annotated @PostMapping("/items") to create one, both technically expressible with @RequestMapping and an explicit method attribute.

@RequestMapping(value = "/example", method = RequestMethod.GET)
public String getExample() { ... }

@RequestMapping(value = "/example", method = RequestMethod.POST)
public String postExample() { ... }

Interview Tip

A concise interview answer is

@RequestMapping's method attribute lets you restrict a handler to a specific HTTP verb, so the same URL path can support GET, POST, PUT, and DELETE through different methods. In practice I use the shortcut annotations like @GetMapping and @PostMapping, which are just @RequestMapping preconfigured with that method attribute.

Last updated: 16 July 2026

Previous question: What are the attributes available in @RequestMapping?

Next question: What are the differences between @Controller and @RestController annotations?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions