gpt4 book ai didi

java - @PathParam 没有给我路径变量

转载 作者:行者123 更新时间:2023-12-02 10:39:46 25 4
gpt4 key购买 nike

我有一个 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 值。我做错了什么?

最佳答案

您导入了错误的@PathParam。它应该是javax.ws.rs.PathParam。您可能正在导入 websocket(当您具有 javaee-api 依赖项时,这是一个常见的错误)。

关于java - @PathParam 没有给我路径变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53008114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com