Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Spring MVC @PathVariable Uses

    • 0
    • 4
    • 6
    • 2
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: