@RequestMapping and @GetMapping are Spring MVC annotations used to map incoming HTTP requests to controller methods. The main difference is that @RequestMapping is a generic mapping annotation capable of handling multiple HTTP methods, whereas @GetMapping is a specialized shortcut annotation specifically designed for handling HTTP GET requests.
What is @RequestMapping?
@RequestMapping is a general-purpose mapping annotation.
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@RequestMapping(
value = "/all",
method = RequestMethod.GET)
public String getEmployees() {
return "Employee List";
}
}In this example, the HTTP method must be specified explicitly.
Supported HTTP Methods
@RequestMapping(
value = "/save",
method = RequestMethod.POST)
What is @GetMapping?
@GetMapping is a shortcut annotation introduced to simplify GET request mappings.
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@GetMapping("/all")
public String getEmployees() {
return "Employee List";
}
}@RequestMapping(
value = "/all",
method = RequestMethod.GET)
but with cleaner syntax.
Internal Relationship
@GetMapping
|
v
@RequestMapping(method = RequestMethod.GET
)
Internally, Spring treats @GetMapping as a specialized version of @RequestMapping.
Comparison
@RequestMapping@GetMapping
Class-Level and Method-Level Usage
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@GetMapping("/{id}")
public String getEmployee() {
return "Employee Details";
}
}/employees/{id}
The class-level mapping acts as a common prefix.
Other Specialized Mapping Annotations
@PostMapping("/save")
@PutMapping("/update")
@DeleteMapping("/delete/{id}")These improve code readability and clearly indicate the intended HTTP operation.
Suppose we expose an Employee API.
@RequestMapping(
value = "/employees",
method = RequestMethod.GET)
@GetMapping("/employees")
Both handle GET requests, but @GetMapping is shorter and easier to understand.
Benefits of @GetMapping
Real-World Example
Retrieve Employees
@GetMapping("/employees")
Create Employee
@PostMapping("/employees")
Update Employee
@PutMapping("/employees/{id}")
Delete Employee
@DeleteMapping("/employees/{id}")Using method-specific annotations makes the API self-explanatory and easier to maintain.
A concise interview answer is
@RequestMapping is a generic annotation that can handle any HTTP method when the method attribute is specified. @GetMapping is a specialized shortcut for handling only HTTP GET requests. Internally, @GetMapping is equivalent to @RequestMapping(method = RequestMethod.GET), but it provides cleaner and more readable code.
Last updated: 11 November 2026
Previous question: What is the difference between @Controller and @RestController?
Next question: What is the difference between @SpringBootApplication and @EnableAutoConfiguration?