For WebService. 1. Path
@javax. Ws.rs.Path The URI path that identifies the resource class or resource method to be requested.
Example, @Path ("animal") that represents the transaction to be processed when the next level path is animal.
@Path ("{species}") This notation with curly braces means that the next path is parameterized, with @pathparam ("species") using parameters that can be assigned to a function.
For code:
@Path ("Animal") public
class Animal {public
String species,name;
public int age;
public static Animal animal=new Animal ();
@GET
@Path ("{species}")
@Produces (mediatype.application_json) public
Animal Wsanimal (@PathParam (" Species ") string species,
@QueryParam (" name ") string name,
@QueryParam (' age ') int age
) {
animal.species=species;
Animal.name=name;
animal.age= age==0?2:age;
return animal
}
}
The effect is shown in Figure 1-1:
Figure 1-1 @Path Usage Example
2. From message data to method parameters
@javax. Ws.rs.PathParam binds the path parameter specified in the URI to the resource method parameter, the field of the resource class, or the Bean property of the resource class.
@javax. ws.rs. Queryparam
Assign the query parameter of the HTTP request to the parameter of the function.
@javax. Ws.rs.DefaultValue
Sets the default value for the @queryparam parameter. If @queryparam does not receive a value, the default value is used. Like what:
public string Fun (@DefaultValue ("description") @QueryParam ("desc") string desc) {...}
@javax. ws.rs. Formparam
Assign the parameters in the form form of the HTTP request to the parameters of the function.
@avax. Ws.rs.Context
Used to get environment information. An example of obtaining a client IP is shown below:
@Path ("util") public
class Util {
@Path ("Getclientip")
@GET
@Produces (mediatype.text_plain)
Public String Getclientip (@Context httpservletrequest request) {return
request.getremoteaddr ();
}
}
3.http Method
@javax. Ws.rs.GET
Indicates that this method responds to an HTTP GET request.
@javax. Ws.rs.POST
Indicates that this method responds to an HTTP POST request.
@javax. Ws.rs.PUT
Typically used to update data.
@javax. Ws.rs.DELETE
Typically used to delete data. 4. Return Data type
@javax. ws.rs.Produces
Set up HTTP return message, Report style content type.
The value is Javax.ws.rs.core.MediaType.XXX. Commonly used are:
Mediatype.application_json
Mediatype.text_plain