Comparison of @QueryParam and @pathparam __java

Source: Internet
Author: User
1 first to see @queryparam
Path ("/users") public class UserService {@GET @Path ("/query") public Response getusers (@QueryParam ("from") int from, @Qu Eryparam ("to") int to, @QueryParam ("by") List<string> by ("by") {return Response. status). Entity (" Getusers is called, from: ' + from + ', to: ' + to + ', by ' + orderby.tostring ()). build ();}

URL entered as: 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, the @queryparam specifies that the parameters in the URL are in the form of a key-value pair, whereas in the program
@QueryParam (' from ') int from is the value from which the URL is read out, and in @pathparem, only the value of the parameter appears in the URL, not the key value pair, for example: "/users/2011/06/30"

2, @PathParam example
@GET @Path ("{year}/{month}/{day}") Public Response getuserhistory (@PathParam (' year ') int year, @ Pathparam ("month") int month, @PathParam (' Day ') int day} {String date = year + "/" + month + "/" + Day; return RESPONSE.S Tatus. Entity ("Getuserhistory is called, Year/month/day:" + date). Build ();

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.