【发布时间】:2016-11-25 14:29:46
【问题描述】:
当我添加 POST 正文时,我无法读取路径参数。
public class POJO {
public int id;
public void setId(int id){
this.id = id;
}
}
...
@POST
@Path("/test/{a}/{b}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response test(@PathParam("a") String a, @PathParam("b") String b, POJO pojo){
// a has the value of the POST body
// b is empty
// pojo is null
}
我发布到 /test/x/y
正文:
{
"id" : 1
}
标题:
Content-Type : application/json
我看了例子https://docs.jboss.org/resteasy/2.0.0.GA/userguide/html_single/ 并且无法弄清楚为什么我无法读取路径参数。 这是一个 JBoss 示例:
@POST
@Path("book/{id}/comments")
public void addComment(@PathParam("id") String bookId, Comment comment);
【问题讨论】:
-
bookId 和评论变量在方法执行时不被重视?
-
带有 book id 和 comment 的代码是上面 resteasy 链接中的一个示例。我的代码有参数 a、b 和 pojo
-
我明白了。但是当方法被执行时你的路径参数是否没有被赋值(null)?
-
当我的方法测试被执行时,变量“a”具有 POST 主体的值(应该去 pojo)。变量“b”和“pojo”为空。
-
你的代码看起来不错。你能展示进口吗?问题可能就在那里。
标签: java rest wildfly resteasy