Posts

Showing posts with the label RequestMapping

Spring RequestMapping, GetMappin, PostMapping annotations

In this blog post, I will be explaining the RequestMapping, GetMapping and PostMapping annotations in Spring. In order to know more about other Spring annotations, you can refer to this article. In order to learn about the Spring framework from scratch, I recommend that you enroll in this Spring masterclass . You can use the RequestMapping, GetMapping and PostMapping annotations to map a URL to a particular Controller method. However, there are some differences between them. Let’s check them out. Edit RequestMapping The RequestMapping annotation can be used to map both GET and POST requests. Consider the following code: @RequestMapping(value="/person/{personId}",method=RequestMethod.GET) public Person getPersonWithId(@PathVariable Integer personId){ } Here, the RequestMapping annotation is used on the getPersonWithId method. It maps to the /person/{personId} URL. The method attribute is also specified. This indicates that this method maps to an HTTP GET request...