我有一个 POST 方法(它需要一些 JSON 数据)。我还想访问路径参数“id”以进行处理。但是,当我使用“@PathParam”时,我得到了传递给请求的 JSON 正文。下面是我的代码:
@Path("/products")
public class PurchaseService {
@POST
@Consumes("application/json")
@Path("{id}/purchase")
@Produces(MediaType.APPLICATION_JSON)
public String doPurchaseForUser(@PathParam("id") String id) {
String result = null;
System.out.println("Product : " + id);
return id;
}
}
如果我将 POST 正文作为 - {"user_id":123} 传入,则上面代码中的 id 变量将保存此值,而不是来自 URI 的 id 值。我究竟做错了什么 ?
牛魔王的故事
拉莫斯之舞
相关分类