Source: http://jackyrong.iteye.com/blog/1128364
1 See @queryparam first.
- Path ("/users")
- public class UserService {
- @GET
- @Path ("/query")
- Public Response Getusers (
- @QueryParam ("from") int from,
- @QueryParam ("to") int to,
- @QueryParam ("list<string>") {
- Return Response
- . Status (200)
- . Entity ("Getusers is called, from: ' + from + ', to: ' + to
- + ", by" + orderby.tostring ()). build ();
- }
- }
URL input is: users/query?from=100&to=200&orderby=age&orderby=name
At this point, the output is:
Getusers is called, from:100, to:200, Orderby[age, name]
Note that, unlike @pathparam, @queryparam specifies that the parameters in the URL appear as key-value pairs, while in the program
The @QueryParam ("from") int from is the value of the from in the URL, whereas in @pathparem, only the value of the parameter appears in the URL, no key-value pairs, such as "/users/2011/06/30"
2, @PathParam example
- @GET
- @Path ("{year}/{month}/{day}")
- Public Response Getuserhistory (
- @PathParam ("year") int of year,
- @PathParam ("month") int month,
- @PathParam ("day") int day) {
- String date = year + "/" + month + "/" + day;
- Return Response.Status (200)
- . Entity ("Getuserhistory is called, Year/month/day:" + date)
- . build ();
- }
Comparison between @QueryParam and @pathparam