Request Mapping
Master Spring MVC request mapping - how to map HTTP requests to controller methods using @RequestMapping, @GetMapping, @PostMapping, and the full range of mapping options.
Last reviewed: January 2025
🔍 What Is It?
@RequestMapping in Spring Boot is the annotation-based routing system that tells Spring Boot which controller method should handle a specific HTTP request. When developers search for @RequestMapping in Spring Boot, they usually want to understand how path patterns, HTTP methods, and controller design work together.
Quick Facts
- →Used in: REST controllers, web MVC endpoints, versioned APIs, and content-type specific handlers
- →Best for: Building clear controller routes with explicit HTTP method behavior
- →Interview importance: High because request mapping is a common Spring Boot interview topic
- →Production relevance: High because API contracts, routing safety, and handler clarity depend on it
- →Related topics: Controllers, path variables, request params, exception handling
- →Last updated: July 2026
Mapping annotations
- →
@RequestMapping(path, method, consumes, produces, headers, params)- most flexible - →
@GetMapping- shorthand for @RequestMapping(method=GET) - →
@PostMapping- shorthand for @RequestMapping(method=POST) - →
@PutMapping- shorthand for @RequestMapping(method=PUT) - →
@DeleteMapping- shorthand for @RequestMapping(method=DELETE) - →
@PatchMapping- shorthand for @RequestMapping(method=PATCH)
Mapping options
- →Path:
/users,/users/{id},/users/** - →Method: GET, POST, PUT, DELETE, PATCH
- →Consumes:
application/json,multipart/form-data - →Produces:
application/json,application/xml - →Headers: require specific request headers
- →Params: require specific query parameters
🎯 Why Do We Need It?
Request mapping provides the routing contract for your Spring Boot API. Without it, there is no clear way to connect an HTTP request to the controller method that should validate input, call business logic, and shape the response.
Interview Relevance
- →Interviewers ask request mapping to test whether you understand controller design, REST conventions, and handler selection
- →Strong answers explain class-level versus method-level mappings, path variables, consumes or produces rules, and shortcut annotations
- →Senior discussions often move into ambiguous mappings, API versioning, validation, and public contract stability
🏗️ What Happens in Real Projects?
Production Usage
Every REST API endpoint is defined by a combination of HTTP method + URL path:
- →
GET /api/v1/users- list users - →
GET /api/v1/users/{id}- get user by ID - →
POST /api/v1/users- create user - →
PUT /api/v1/users/{id}- replace user - →
PATCH /api/v1/users/{id}- partial update - →
DELETE /api/v1/users/{id}- delete user
Production teams also use request mapping to control media types, route versioning, nested resources, and backward-compatible endpoint evolution across multiple clients.
⚙️ How It Works
Spring's DispatcherServlet receives every HTTP request. It consults the HandlerMapping built from your @RequestMapping annotations to find the matching controller method. If multiple methods match, Spring uses specificity rules to pick the best match. If no match is found, 404 is returned.
@RequestMapping vs @GetMapping
- →
@RequestMappingis the flexible base annotation for path, method, headers, params, consumes, and produces - →
@GetMapping,@PostMapping,@PutMapping, and the others are shortcuts that make REST controller methods easier to scan quickly
💻 Example
Request Mapping Patterns — Common mapping patterns used in enterprise REST APIs.
🤔 Common Confusions
❓ What is the difference between @RequestMapping on class vs method?
@RequestMapping on the class defines the base path for all methods in that controller. Method-level annotations add to that base path. @RequestMapping("/api/v1/users") on the class + @GetMapping("/{id}") on a method = GET /api/v1/users/{id}.
❓ When should I use PUT vs PATCH?
PUT replaces the entire resource - the client sends the complete new state. PATCH partially updates - the client sends only the fields to change. In practice, many APIs use PUT for both. PATCH is more RESTful for partial updates but requires more careful implementation, especially around null versus missing fields.
🚨 Common Production Issues
Ambiguous mapping exceptions appear when two controller methods match the same URL and HTTP method combination.
Trailing slash mismatches can make /users and /users/ behave differently if clients and server configuration are not aligned.
Case-sensitive URL matching can cause avoidable 404 responses when public clients use inconsistent casing.
✅ Best Practices
Use specific method annotations such as @GetMapping instead of generic @RequestMapping whenever possible.
Put the base path on the class and the operation-specific route on the method.
Use lowercase, hyphenated URLs such as /user-profiles instead of /userProfiles.
Version public APIs early, for example with /api/v1/.
Be explicit with consumes and produces rules for non-JSON endpoints.
🏛️ Architect's Note
Consistent URL naming is an API contract. Once published, you cannot change endpoints casually without breaking clients. Establish naming conventions early: plural nouns for resources, lowercase with hyphens, and clear versioning from day one. Nested paths are useful, but keep them shallow enough that the resource model stays understandable.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
Spring Boot Technology Guide
Return to the Spring Boot learning hub.
Backend Engineer Career Path
A structured journey through Core Java, Spring Boot, production backend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Sources
Sources / References
Use these Spring Boot references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide Spring Boot learning path
Browse the full Spring Boot topic collection and learning order on SplashRide.
Spring Boot Interview Prep
Practice Spring Boot interview questions and scenario-based answers.
Backend Engineer Career Path
A structured journey through Core Java, Spring Boot, production backend engineering, and interview preparation.
Full Stack Java Developer Career Path
A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.
Controllers
Master Spring MVC Controllers — the web layer that handles HTTP requests, maps URLs to methods, and returns responses in enterprise REST APIs.
Spring @RequestParam
Learn how @RequestParam works in Spring Boot with query parameters, optional params, default values, list filters, form binding, and REST API examples.