【发布时间】:2018-04-11 06:12:08
【问题描述】:
我是 REST API 的新手。 我正在开发一个 REST API。 在以下 API 中,我采用的参数是 cloud-id。
这是 API 调用:
@GET
@Path("{cloud-id}")
@Produces("application/json")
public Object Getall(@PathParam("cloud-id") String cloudID) {
if(cloudID!=null){
//return some details
}else{
//return something else
}
}
快乐之路:
http://example.com/sampleCloudID
这也很好用
http://example.com/(sampleCloudID)
It gives a 404 as expected
但是当我给出 URI 时
http://example.com/{sampleCloudID}
错误:
You specified too few path parameters in the request.
如果我收到的输入是 {samplecloudID},我希望服务返回 404,但如果路径变量在 {} 中,我将无法访问我的资源。
为什么花括号给我一个错误,但正常括号给我预期的 404?
【问题讨论】:
-
您应该使用 url 作为顶部的
http://example.com/sampleCloudID。括号仅在代码中使用,因此您可以将@PathParam作为参数添加到您的方法中
标签: java spring rest get jax-rs