Spring Request Params and Request Map


Spring Request Params and Request Map

The @RequestParam annotation in Spring MVC is used to receive form data and immediately tie it to the parameter in the given method. As a result, it disregards the HttpServletRequest object's need to read the given data.

It also translates request parameters to query parameters and portions in multipart requests, as well as form data. The request parameter value is transformed to a Map if the method parameter type is Map and a request parameter name is given, else the map parameter is populated with all request parameter names and values.

@RequestParam

Request handler method parameters are annotated with this annotation. In certain cases, the parameters are included in the request URL, which is most frequent in GET requests. You may use the @RequestParam annotation in conjunction with the @RequestMapping annotation to get the URL parameter and map it to the method argument in that scenario.

Composed @RequestMapping Variants

The following method-level versions of the @RequestMapping annotation were introduced in Spring Framework 4.3 to better describe the semantics of the annotated methods. Using these annotations has become the standard way of defining the endpoints. They act as a wrapper to @RequestMapping.Request parameters are bound to a method parameter in your controller using the @RequestParam annotation.

Spring MVC and Spring WebFlux can both benefit from these annotations.

@GetMapping

    This annotation is used to bind certain handler methods to HTTP GET requests.
    @RequestMapping(method = RequestMethod.GET) is a constructed annotation that works as a shortcut for @GetMapping.

@PostMapping

    This annotation is used to bind certain handler methods to HTTP POST requests.
    @RequestMapping(method = RequestMethod.POST) is a constructed annotation that works as a shortcut for @PostMapping.

@PutMapping

    HTTP PUT requests are mapped to specified handler methods using this annotation.
    @RequestMapping(method = RequestMethod.PUT) is a constructed annotation that works as a shortcut for @PutMapping.

@PatchMapping

    HTTP PATCH requests are mapped to particular handler methods using this annotation.
    @RequestMapping(method = RequestMethod.PATCH) is a constructed annotation that works as a shortcut for @PatchMapping(method = RequestMethod.PATCH).

@DeleteMapping

    HTTP DELETE requests are mapped to specified handler methods using this annotation.
    @DeleteMapping is a constructed annotation that replaces @RequestMapping(method = RequestMethod.DELETE) with @DeleteMapping(method = RequestMethod.DELETE).