Skip to content

Function Annotations

AyushiDamele edited this page Mar 2, 2021 · 2 revisions

@RequestParam annotation used for accessing the query parameter values from the request. Look at the following request URL:

The following are the list of parameters supported by the @RequestParam annotation:

  • defaultValue – This is the default value as a fallback mechanism if request is not having the value or it is empty.
  • name – Name of the parameter to bind
  • required – Whether the parameter is mandatory or not. If it is true, failing to send that parameter will fail.
  • value – This is an alias for the name attribute

@PathVariable identifies the pattern that is used in the URI for the incoming request.

Let’s look at the below request URL: http://localhost:8080/springmvc/hello/101?param1=10&param2=20 @RequestMapping("/hello/{id}") public String getDetails(@PathVariable(value="id") String id, @RequestParam(value="param1", required=true) String param1, @RequestParam(value="param2", required=false) String param2) { ....... }

Clone this wiki locally