我有以下代码作为我的 restful 服务操作。
@GET
@UnitOfWork
@Timed(name = "get-requests")
@Path("/{referenceId}")
public Response get(@Auth @ApiParam(access = "internal") UserPrincipal user,
@ApiParam(name = "id", value = "reference ID", required = true)
@PathParam("referenceId") String id) {
return Response.ok(id).build();
}
但是,我注意到如果我传入 m1234;5678
,我只会返回 m1234
。我尝试了 @Path("/{referenceId:.*}")
,但它不起作用。
我还尝试在方法顶部使用 @Encode
以确保 url 未被解码,然后尝试将 %3B
替换为“;”在代码中。但它似乎也不起作用。
请注意,我不能使用 Spring 框架。谢谢。
最佳答案
;
表示一个矩阵参数。使用 @MatrixParam
获得它的值(value)。
另请参阅此问题的答案:URL matrix parameters vs. request parameters
编辑:矩阵参数的键将为5678
,值为null
。
有一种方法可以通过使用 PathSegment
来实现您想要的效果作为参数的 type 而不是 String
:
@PathParam("referenceId) PathSegment id
在方法体中,可以使用
String idValue = id.getPath();
获取 m1234;5678
。
关于java - restful 服务 URL 中的分号截断其后的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931491/