DEV Community

Cover image for @GetMapping Annotation in Spring Boot
Ezhil Abinaya K
Ezhil Abinaya K

Posted on

@GetMapping Annotation in Spring Boot

In Spring Boot, @GetMapping is annotations used to handle HTTP requests in Spring MVC controllers. They help map specific HTTP methods to controller methods when building REST APIs.@GetMapping is used to retrieve data from the server.
GetMapping annotation
@GetMapping in Spring is used to handle HTTP GET requests in RESTful web services. It maps a specific URL to a controller method that retrieves data from the server.

  • Used to retrieve or read data from the server.
  • Parameters are usually passed through URL path variables or query parameters.
@GetMapping("/students")
public List<Student> getAllStudents() {
 return studentRepository.findAll();
}
Enter fullscreen mode Exit fullscreen mode

getAllStudents method is annotated with @GetMapping annotation. This means that getAllStudents method will be called when an HTTP Get request is received at the /students URL.
Reference
https://www.geeksforgeeks.org/advance-java/spring-postmapping-and-getmapping-annotation/

Top comments (0)