如何在POST请求中的请求正文中发送多个参数?
@POST
@Consumes("multipart/form-data")
@Produces("application/json")
public String addForm1(@FormParam("i1") Integer i1, @FormParam("i2") Integer i2);
上面的代码返回HTTP 415.
用@Multipart替换@FormParam会导致Resource方法有多个表示请求正文错误的参数,如下所示.
SEVERE: Resource method service.rs.TestService.postData2 has more than one parameter representing a request body
Exception in thread "main" org.apache.cxf.jaxrs.client.ClientWebApplicationException: Resource method service.rs.TestService.postData2 has more than one parameter representing a request body
at org.apache.cxf.jaxrs.client.ClientProxyImpl.reportInvalidResourceMethod(ClientProxyImpl.java:546)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.getParametersInfo(ClientProxyImpl.java:214)
at org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:138)
at $Proxy20.postData2(Unknown Source)
at service.TestServiceClient.main(TestServiceClient.java:82)
此外,我需要做什么才能传递多个复杂类型,例如List< Map< String,String>>’或’List< MyNestedCustomObject>在POST方法?我可以通过使用JAXB并使用@XmlJavaTypeAdapter注释它来传递这样的参数,但我想这在传递多个参数的情况下不起作用?我是否需要定义自己的消息体阅读器&作家呢?任何示例代码都很有用.
谢谢