DEV Community

Cover image for Spring - @RequestMapping
Yiğit Erkal
Yiğit Erkal

Posted on

Spring - @RequestMapping

TL;DR

It is used to map web requests to Spring Controller methods.

In Spring Web applications, @RequestMapping is one of the most used annotations. HTTP requests are mapped to MVC and REST controller handler methods with this annotation.

URL handler using @RequestMapping annotation as it follows here:

@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
Enter fullscreen mode Exit fullscreen mode

The alternative approach in other words possible short version is:

@GetMapping("/get/{id}")
Enter fullscreen mode Exit fullscreen mode

We can also implement other mappings mentioned below:

RequestMapping Spring Annotation

To sum up, it is a better approach to use RequestMapping or alternative mapping in class level controllers since all your requests and responses will be handled in controller. Here is a full code example:

@Controller
@RequestMapping(value = "/orders", method = RequestMethod.GET)
public class DemoController {


  @RequestMapping(value = "/{orderId}", method = RequestMethod.GET)
  @ResponseBody
  public String getOrder(@PathVariable final String orderId) {
    return "Order ID: " + orderId;
  }

  @RequestMapping(value = "/addProduct", method = RequestMethod.POST)
  public String addProductPost(@ModelAttribute("product") 
Product product) {
    // some code
}

 // other mappings
 // ...
}
Enter fullscreen mode Exit fullscreen mode

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay