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

    • 0
    • 2
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 536
    Comment on it

    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)

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: