0

我有以下球衣方法声明:

    @POST
    @Path("/fooPath")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    public Response isSellableOnline(@FormParam("productCodes") final List<String> productCodes,
                                     @FormParam("storeName") final String storeName,
                                     @Context HttpServletRequest request) {

在休息客户端中,我尝试像这样调用以下方法: 在此处输入图像描述

当我调试方法时,我看到接收到的参数为空:

在此处输入图像描述

如何重写方法声明?

4

1 回答 1

3

这是因为在 isSellableOnlie 方法上您期望或尝试提取表单参数,但传入的 POST 请求是 JSON。

好吧,如果你想要 JSON,你应该让 POJO 类能够序列化 JSON。

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Store {

private String storeName;
private List<String> productCodes;

public Store() {
}

public String getName() {
    return name;
}

public List<String> getProductCodes() {
    return productCodes;
}
}

然后在你的方法中:

@POST
@Path("/fooPath")
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
public Response isSellableOnline(Store store) {
   store.getName();
...
}
于 2015-01-22T08:51:30.660 回答