First, @pathparam
@PathParam is a parameter annotation that maps a parameter on a URL to a method parameter, which can be mapped to a type of a method parameter with a base type, a string, or any Java object that has a string as a constructor parameter, Or a Java object that has a static method that has a string as an argument valueOf (typically gets the parameter value from the Get URL).
@GET @Path ("Delprobypnumber/{param}") @Produces ("Application/json; Charset=utf-8 ") Public Response DelPro (<strong> @PathParam (" param ") String pnumber</strong>) { session.delete ("Production.delete", pnumber); Session.commit (); List List=queryallpro (); return Response.Status (201). Entity (list). build (); }
Access path: http://localhost:8888/Invoice/optPro/delprobypnumber/7
@pathparem, only the value of the parameter appears in the URL, no key-value pairs, such as: "/users/2011/06/30"
@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. Entity ("Getuserhistory is called, Year/month/day:" + date). Build (); }
In addition: {var} represents only one pathname, such as: A, and {var:.*} can be any number of pathname, such as: a/b/c
/** * {var:.*} can represent any number of pathname, such as: A/B/C */@Path ("/pathregular1/{var:.*}/{msg}") @GETpublic String pathRegular1 (@PathParam ("MSG") String m) { return m;} /** * {var} represents only one pathname, such as: a*/@Path ("/pathregular1/{var}/{msg}") @GETpublic String pathRegular2 (@PathParam ("MSG") String m) { return m;}
Second, @queryParam
@queryParam get parameters from/xxx/path/? num=5
@GET @Path ("Addacc/parameters") @Produces ("Application/json; Charset=utf-8 ") Public Response Addcus ( @QueryParam (" Accname ") String Accname, @QueryParam (" balance ") Long balance, @QueryParam ("department") String Department, ) {account account=new account (); Account.setaccname (accname); Account.setbalance (balance); return Response.Status (201). Entity (Queryone (Accname)). Build ();}
Access Path: http://localhost:8888/Invoice/optAcc/addAcc/parameters? accname=rr&balance=99999&department= Heda,parameters back for incoming parameters
Path ("/users") public class UserService { @GET @Path ("/query") public Response getusers ( @ Queryparam ("from") int from, @QueryParam (' to ') int to, @QueryParam ("by") list<string>) { return Response.Status (+). Entity ("Getusers is called, from: ' + from + ', to: ' + to + ', ' by ' + '). ToString ()). build ();
The URL input is: users/query? from=100&to=200&orderby=age&orderby=name At this point, the output is: Getusers was called, from : to:200, Orderby[age, name].
Note: Unlike @pathparam, @queryparam specifies that the parameters in the URL appear as key-value pairs , while in the program @QueryParam ("from") an int from reads out the value from the URL
Third, @FormParam
The fields in the form are mapped to method calls and are generally submitted as post for such a way.
For example, for the following form:
<form method= "POST" action= "/resources/service" >first Name: <input type= "text" name= "FirstName" ><br >last Name: <input type= "text" name= "LastName" ></form>
Submitted through the Post method, the method for processing the request is:
The Path ("/") public class Nameregistry { @Path ("/resources/service") @POST the public void AddName (@FormParam (" FirstName ") string first, @FormParam (" LastName ") string last) {...}}
Access path: http://localhost:8888/resources/services/hello/getname
You can also add application/x-www-form-urlencoded to deserialize multiple parameters in the URL:
@Path ("/") public class Nameregistry { @Path ("/resources/service") @POST @Consumes ("application/ x-www-form-urlencoded ") Public void AddName (@FormParam (" FirstName ") String first, multivaluedmap<string, string> form) {...}}
See also: http://blog.csdn.net/programmeryu/article/details/50536024
http://ju.outofmemory.cn/entry/144017
http://www.cnphp6.com/archives/29400
Resteasy Value-Transfer method