用Java传递REST参数

用Java传递REST参数,java,rest,parameters,Java,Rest,Parameters,我用一些webmethods构建了一个RESTWebService。 但我无法将参数传递给这些方法 即 我将如何调用该方法以及如何传递参数firstname和lastname? 我试过这样的方法: ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); ClientR

我用一些webmethods构建了一个RESTWebService。 但我无法将参数传递给这些方法

我将如何调用该方法以及如何传递参数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);
但是我在哪里添加参数呢

谢谢你的帮助, 顺致敬意,
克里斯的教程应该会有所帮助。要包含参数,您需要使用前面SO帖子中所示的
@PathParam
命令。

如果您使用SpringMVC进行REST api开发,您可以使用

@RequestParam("PARAMETER_NAME");
@QueryParam("PARAMETER_NAME");
如果是运动衫,您可以使用

@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");

谢谢你帮了我很多。但是如果我的方法需要一个字符串数组呢?@Chris:这应该会有帮助:非常感谢。这个链接对你上一个链接的上下文也很有帮助:这对我来说似乎很有希望,但在Android中似乎没有ClientResponse。。。