Sometimes we need to pass parameters along with the url to get the data. In Spring MVC framework, we can customize the URL in order to get data. For this purpose @PathVariable annotation is used in Spring framework.
For example you want to write a url to get user's details as below
http://localhost:8080/app/findMe/user@gmail.com
where user@gmail.com is user's emailId.
Now we'll define this url in Spring MVC controller as below:
/findMe/{emailId}
We'll declare emailId as path variable:
@RequestMapping(value = "/findMe/{emailId:.+}", method = RequestMethod.GET)
public ModelAndView findMe(HttpServletRequest request,
HttpServletResponse response,@PathVariable String emailId)
{
}
As you can see in the above example emailId is a PathVariable, so if we use url http://localhost:8080/app/findMe/user@gmail.com, then emailId variable will be populated by value user@gmail.com.
Hope this will help you :)
0 Comment(s)