← All tutorials

GoCareerGo Tutorials

Spring Boot Tutorial

Auto-configuration, REST APIs, JPA, AOP, caching, microservices and Spring Cloud.

@RequestMapping, @GetMapping, @PostMapping

Annotations that map an incoming HTTP request (method + path) to a specific controller method.

@RequestMapping("/api/orders")     // base path for the whole class
@GetMapping                          // GET /api/orders
@GetMapping("/{id}")                // GET /api/orders/{id}
@PostMapping                         // POST /api/orders
@PutMapping("/{id}")                // PUT /api/orders/{id}
@DeleteMapping("/{id}")             // DELETE /api/orders/{id}
  • @GetMapping/@PostMapping/etc. are shorthand for @RequestMapping(method = ...)
  • Class-level @RequestMapping sets a shared base path for every method below it