@GetMapping Spring Boot Example

Spring @GetMapping example shows how to use @GetMapping annotation to map HTTP GET requests onto specific handler methods.

@GetMapping Overview

@GetMapping annotation maps HTTP GET requests onto specific handler methods. It is a composed annotation that acts as a shortcut for @RequestMapping(method = RequestMethod.GET).
@GetMapping - shortcut for @RequestMapping(method = RequestMethod.GET)

@GetMapping Example

@GetMapping annotation for mapping HTTP GET requests onto specific handler methods.
In the below example, the @GetMapping annotation mapping HTTP GET "/employees" and "/employees/{id}" requests onto specific handler methods getAllEmployees and getEmployeeById:
public List<Employee> getAllEmployees() {
     return employeeRepository.findAll();

public ResponseEntity<Employee> getEmployeeById(@PathVariable(value = "id") Long employeeId)
 throws ResourceNotFoundException {
     Employee employee = employeeRepository.findById(employeeId)
       .orElseThrow(() -> new ResourceNotFoundException("Employee not found for this id :: " + employeeId));
     return ResponseEntity.ok().body(employee);
Check out a complete example at Spring Boot 2 Hibernate 5 MySQL CRUD REST API Tutorial


Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course