JAX-RS @ matrixParam and @ PathParam

Source: Internet
Author: User

Continue Learning jboss reseteasy parameters today. What we want to learn today is @ PathParam
And @ matrixParam

1) @ pathparam
First look at the example:
@ Path ("/users ")
Public class UserRestService {

@ GET
@ Path ("{id }")
Public Response getUserById (@ PathParam ("id") String id ){

Return Response. status (200). entity ("getUserById is called, id:" + id). build ();

}

}
The URL is as follows:
/Users/22667788"
Match (@ PathParam ("id") String id)
Therefore, output:
GetUserById is called, id: 22667788

2) @ pathparam matches multiple output parameters:
@ Path ("/users ")
Public class UserRestService {

@ 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. status (200)
. Entity ("getUserHistory is called, year/month/day:" + date)
. Build ();

}

}
URl: "/users/2011/06/30"
Matching:
GetUserHistory is called, year/month/day: 2011/6/30

3) matrixparam
This is mainly for splitting parameters, such:
@ GET
@ Path ("{year }")
Public Response getBooks (@ PathParam ("year") String year,
@ MatrixParam ("author") String author,
@ MatrixParam ("country") String country ){

Return Response
. Status (200)
. Entity ("getBooks is called, year:" + year
+ ", Author:" + author + ", country:" + country)
. Build ();

}

URL:
"/Books/2011 /"
Result:
GetBooks is called, year: 2011, author: null, country: null

URL:/books/2011; author = mkyong; country = malaysia
Result:
GetBooks is called, year: 2011, author: mkyong, country: malaysia

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.