I want to pass variables in Java Rest API The Post URL is : ex: https://localhost:8080/webresources/test?id=.....
This is my current code:
@POST
@Path("test")
public String newRequest() throws ServletException, IOException, JSONException {
...
}
How should I pass my parameter to call my request like this : newRequest(123) ;
You want to add @QueryParam for query parameters, as:
public String newRequest(@QueryParam("id") String request_sf_id) throws ServletException, IOException, JSONException { ..}
Binds the value(s) of a HTTP query parameter to a resource method parameter, resource class field, or resource class bean property.
You can use RequestParam:
@POST
@Path("test")
public String newRequest(@RequestParam(value ="id") String id) throws ServletException, IOException, JSONException {
...
}
And calling :
https://localhost:8080/webresources/test?id=.....
Please note, RequestParam is part of spring so you need :
import org.springframework.web.bind.annotation.RequestParam;
@POST @Path("newrequest") public String newRequest( @HeaderParam( "request_sf_id") String request_sf_id) throws ServletException, IOException, JSONException { ... }
This is my answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.