What is difference between Getmapping and Postmapping in Spring?


Posted On: Feb 22, 2018


Major difference between Getmapping and Postmapping

Getmapping: Getmapping is a Spring notation and is widely used in mapping HTTP GET requests onto some specific handler methods. Getmapping is not generally used in mapping handler classes. This feature differentiates getmapping and requestmapping annotation from each other. It can be considered as an annotation that acts as a shortcut of requestmapping annotation. Getmapping requests handler paths onto specific handler methods. The lines of code are comparatively less than that of requestmapping.

Its request method can be framed as method= RequestMethod.GET. Getmapping is a newer annotation that has been developed to overcome the drawbacks of the previous requestmapping. It supports several attributes such as consume like @requestmapping. It is used to determine or map the GET & POST requests together and its method attribute is also not specified as getmapping maps to HTTP Get method always. This is composed of notation that acts as a shortcut for @requestmapping (method = RequestMethod.Get) it is used to get the requests on well defined and specific handler methods. In this notation it supports consumes where the options are-

consumes = "text/plain"
consumes = {"text/plain", "application/*"}

Postmapping: The latest version of Spring MVC known as Spring 4.3 bought with it some annotations, and postmapping is one of them. It has the same purpose as @requestmapping . Postmapping along with other new annotations is meta annotated. These annotations are meta-annotated with @requestmapping as per the related value of the "method " element. Postmapping depicts a combination of notation which is also an abbreviation for @requestmapping.

It is used to map out the Get requests only and its method attribute is also not specified as postmapping always maps HTTP post methods. It is composed of a notation that acts as a shortcut for @requestmapping ( method= RequestMethod. Post). When we talk about the shortcut for @requestmapping we talk about @postmapping, it is a composed annotation that can act as it’s shortcut as @ReqeustMapping(method= RequestMethod.POST).

Variants of @requestmapping other than @getmapping and @postmapping are @patchmapping@putmapping, and @deletemapping.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Spring Interview Questions

    What are the features/ characteristics of spring?

    The important features of spring are as follows:Lightweight: Considering transparency and size, spring is lightweight..

    Spring Interview Questions

    How many types of modules are there in spring? Name them.

    There are around twenty modules, which can be categorized into Core Container, Web, Data Access or Integration, Aspect ..

    Spring Interview Questions

    What do you mean by Spring Java Based Configuration?

    Spring configuration files are XML files. These files contain the information of classes and describe how these classes..