@QueryParam
时间: 2023-12-07 18:54:53 浏览: 81
@QueryParam is a JAX-RS annotation used to extract query parameters from the URL of a RESTful web service endpoint. It is used to define a method parameter that will receive the value of a query parameter.
For example, consider a RESTful web service endpoint that accepts a GET request with two query parameters: "name" and "age". We can define a method parameter for each query parameter using the @QueryParam annotation:
```
@GET
@Path("/user")
public Response getUser(@QueryParam("name") String name, @QueryParam("age") int age) {
// Method implementation
}
```
In this example, the getUser() method will extract the values of the "name" and "age" query parameters from the URL of the request and assign them to the corresponding method parameters.
If the URL of the request is "/user?name=John&age=30", the value of the "name" parameter will be "John" and the value of the "age" parameter will be 30.
If a query parameter is not present in the URL, the corresponding method parameter will be null (if it is a reference type) or have its default value (if it is a primitive type).