Method-level mappings let a single controller class expose multiple endpoints, each handled by its own method, by annotating each method with a request-mapping annotation that specifies a URL pattern and HTTP method. This keeps related endpoints grouped together while still routing each request precisely.
A UserController might use a class-level @RequestMapping("/users") combined with @GetMapping("/{id}") for fetching a user and @PostMapping for creating one, keeping all user-related endpoints in one class.
@RestController
@RequestMapping("/users")
public class UserController {
@GetMapping("/{id}")
public User getUser(@PathVariable Long id) { ... }
@PostMapping
public User createUser(@RequestBody User user) { ... }
}A concise interview answer is
I define method-level mappings with @GetMapping, @PostMapping, and similar shortcut annotations, often combined with a class-level @RequestMapping base path. Each method's annotation specifies both the URL pattern and the HTTP verb it handles, so Spring can route each incoming request to exactly one method.
Last updated: 11 November 2026
Previous question: Explain the purpose of the @RequestMapping annotation.
Next question: What are the attributes available in @RequestMapping?