For Get request we need to pass parameters as request param along with the url to get the data. In Spring MVC framework, we can customize the URL in order to get data. To read the parameters passed with the URl we use @RequestParam in Spring framework. @RequestParam binds a request parameter to a parameter in your method.
For example you want to write a url to get user's details by userId as below
http://localhost:8080/app/user/getuserDetails?userId=18
Now we'll define this url in Spring MVC controller as below:
/user/getuserDetails
We'll declare emailId as path variable and will define createdDate as request param:
@RequestMapping(value = "/user/getuserDetails", method = RequestMethod.GET)
public ModelAndView getuserDetails(HttpServletRequest request,
HttpServletResponse response,@RequestParam(value = "userId", required = false) int userId)
{
}
As you can see in the above example "userId" is is a RequestParam, so if we use url http://localhost:8080/app/user/getuserDetails?userId=18, then the value of the parameter named "userId" will be passed as the "userId" argument in the above method.
Hope this will help you :)
0 Comment(s)