您可以DELETE
使用@PathParam
(推荐)或@QueryParam
使用@PathParam(推荐)
端点:url/:id
@DELETE
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public void deletePathParam(@PathParam("id") int id) {
...
}
测试:
@Test
public void testDeletePathParam() {
Response output = target(url+"/3").request().delete();
// asserts
}
使用@QueryParam(糟糕的 RESTapi 设计)
端点:url?id=:id
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void deleteQueryParam(@QueryParam("id") int id) {
...
}
测试:
@Test
public void testDeleteQueryParam() {
Response output = target(url).queryParam("id", 3).request().delete();
// asserts
}