Google News
logo
Java Spring MVC - Interview Questions
What is the @RequestParam used for?
The @RequestParam is a Spring MVC annotation that is used to extract a request parameter or query parameters from the URL in the Controller's handler method as shown below : 
 
public String personDetail(@RequestParam("id") long id){
  ....
  return "personDetails";
}
 
The @RequestParam annotation also supports data type conversion, e.g. you can see here a String is converted to log automatically, but it can also result in an exception if query parameter is not present or in case of type mismatch. You can also make the parameter optional by using requried=false, e.g. @RequestParam  (value="id", required=false )
Advertisement