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