Comparison between @QueryParam and @pathparam

Source: Internet
Author: User

Source: http://jackyrong.iteye.com/blog/1128364

1 See @queryparam first.

  1. Path ("/users")
  2. public class UserService {
  3. @GET
  4. @Path ("/query")
  5. Public Response Getusers (
  6. @QueryParam ("from") int from,
  7. @QueryParam ("to") int to,
  8. @QueryParam ("list<string>") {
  9. Return Response
  10. . Status (200)
  11. . Entity ("Getusers is called, from: ' + from + ', to: ' + to
  12. + ", by" + orderby.tostring ()). build ();
  13. }
  14. }

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

    1. @GET
    2. @Path ("{year}/{month}/{day}")
    3. Public Response Getuserhistory (
    4. @PathParam ("year") int of year,
    5. @PathParam ("month") int month,
    6. @PathParam ("day") int day) {
    7. String date = year + "/" + month + "/" + day;
    8. Return Response.Status (200)
    9. . Entity ("Getuserhistory is called, Year/month/day:" + date)
    10. . build ();
    11. }

Comparison between @QueryParam and @pathparam

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.