What is the difference between @RequestMapping and @GetMapping?

@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.

Key Points

What is @RequestMapping?

@RequestMapping is a general-purpose mapping annotation.

It can be applied at

@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 can handle

Example

@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";
    }
}

This produces the same result as

@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";
    }
}

Generated URL

/employees/{id}

The class-level mapping acts as a common prefix.

Other Specialized Mapping Annotations

Spring provides additional shortcut annotations

Examples

@PostMapping("/save")

@PutMapping("/update")

@DeleteMapping("/delete/{id}")

These improve code readability and clearly indicate the intended HTTP operation.

Example

Suppose we expose an Employee API.

Using @RequestMapping

@RequestMapping(

value = "/employees",

method = RequestMethod.GET)

Using @GetMapping

@GetMapping("/employees")

Both handle GET requests, but @GetMapping is shorter and easier to understand.

Benefits of @GetMapping

Real-World Example

In a RESTful Employee Management application

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.

Interview Tip

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?

More Spring Boot - Level I interview questions

All Spring Boot - Level I questions