【发布时间】:2021-02-07 08:05:55
【问题描述】:
@Path("v2/test”)
Class Test{
@Path(“{id}/{version}”)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getvalue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) {
//do some thing
}
@DELETE
@Path(“{testPath: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("testPath")
String testPath) throws Exception {
//do something
}
}
GET : http://localhost:8080/v2/test/testId/1.0 - 有效
删除:http://localhost:8080/v2/test/testId - 有效
DELETE : http://localhost:8080/v2/test/testId/1.0 - 405 方法不允许错误
当我添加两个删除路径时,我得到 415 错误(相同的 curl 没有版本)
@Path("v2/test”)
Class Test{
@Path(“{id}/{version}”)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getvalue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) {
//do some thing
}
@DELETE
@Path(“{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("id")
String id) throws Exception {
//do something
}
@DELETE
@Path(“{id}/{version}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam(“id”)
String id, @PathParam(“version”)
String version) throws Exception {
//do something
}
}
curl -X DELETE --header 'Content-Type: application/json' http://localhost:8080/v2/test/testId/1.0 - 给我错误'Error 415--Unsupported Media Type'
curl -X DELETE --header 'Content-Type: application/json' http://localhost:8080/v2/test/testId - 工作正常(即使没有 contentType 也能正常工作)
但是如果我删除带有 id 和版本的 Get 方法 DELETE 操作有效
@Path("v2/test”)
Class Test{
@DELETE
@Path(“{testPath: .+}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteValue(@PathParam("testPath")
String testPath) throws Exception {
//do something }
}
删除:http://localhost:8080/v2/test/testId - 有效
删除:http://localhost:8080/v2/test/testId/1.0 - 有效
有人可以帮助我解决这个问题吗?我想要上述格式的获取和删除方法,我该如何实现?
JDK:1.6 球衣:1.10 服务器:网络逻辑
【问题讨论】:
标签: java rest jersey jax-rs jersey-1.0