Alex Rivera | Logout

In a Spring 3.0 GET request, what's the difference between a @PathVariable and a @RequestParam

Asked 2010-11-01T23:31:04.483
14

In an example such as the following, what's the difference between a @PathVariable and a @RequestParam?

@RequestMapping(value = "/portfolio/{portfolioIdPath}", method = RequestMethod.GET)
public final String portfolio(HttpServletRequest request, ModelMap model, 
@PathVariable long portfolioIdPath, @RequestParam long portfolioIdRequest)
Edit
Report

1 Answer

2

@RequestParam identifies the HTTP GET or POST parameter which is sent by the client(user), And @RequestMapping extracts a segment of URL which varies from request to request:

http://host/?var=1

In the above URL "var" is a requestparam.

http://host/registration/{which}

and above URL's {which} is a request mapping. You could call your service like :

http://host/registration/user

OR like

http://host/registration/firm

In your application you can access the value of {which} (In first case which="user" and in second which="firm".

answered 2010-11-01T23:42:10.747

Your Answer