[英]REST passing Parameters with Java
我已经使用一些webmethods构建了一个REST Web服务。 但是我没有把它传递给这些方法。
IE
@GET
@Path("hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String firstName, String lastName){
return "Hello " + firstname + " " + lastname
}
我将如何调用该方法以及如何传递参数firstname和lastname? 我试过这样的事情:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
ClientResponse response = service.path("hello")
.accept(MediaType.TEXT_PLAIN).put(ClientResponse.class);
但是我在哪里添加参数?
谢谢你的帮助,最好的问候,克里斯
如果您使用SpringMVC进行REST API开发,则可以使用
@RequestParam("PARAMETER_NAME");
如果是运动衫,你可以使用
@QueryParam("PARAMETER_NAME");
方法看起来像这样
public String hello(@RequestParam("firstName")String firstName, @RequestParam("lastName")String lastName){
return "Hello " + firstname + " " + lastname
}
这会对你有所帮助
ClientResponse response = resource.queryParams(formData).post(ClientResponse.class, formData);
其中formData是
MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("Key","Value");
formData.add("Key","Value");
...
...
...
formData.add("Key","Value");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.