我在 RestAPI 中有此方法,该方法更新的 URL 是什么?如何发送用户参数来使用 Postman 测试此方法?
@Path("/resource")
public class MyResource{
@PUT
@Path("edit")
public Response update(@PathParam("id") id , @QueryParam("user")User user){
...
...
}
}
最佳答案
在您的情况下,网址将为/resource/edit/{id} 。
但是,我宁愿建议您将 update() 方法的 @Path 定义为 @Path({id})。因此,URL 将为/resource/{id}。
这将是具有特定 HTTP 方法类型的所有 CRUD 操作的 URL。例如,
/resource/{id} - with HTTP GET to get details
/resource/{id} - with HTTP POST to create a new record
/resource/{id} - with HTTP DELETE to delete the resource
您可以在 postman 的请求正文中传递 User 对象,如下所示(thro' Form-data/raw)。
{"名字":"abc","姓氏":"xyz"}
关于java - Rest API 中更新方法的 URL,将对象作为查询参数发送给它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31236624/