【问题标题】:Resltlet mapping resources with URLs containing queryparam带有包含 queryparam 的 URL 的 Resltlet 映射资源
【发布时间】:2016-04-28 11:34:55
【问题描述】:

我必须开发一个休息网络服务。为此,我使用restlet api。
我有 3 个获取网址:

 1. /info/person?name=aaa
 2. /info/person?name=aaa&age=21
 3. /info/person?name=aaa&age=21&sex=male

我想将这些 url 映射到 3 种不同的资源方法。

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.QueryParam;

@Path("/info/person")
@Produces(MediaType.APPLICATION_XML)
public class TestResource{

//method 1
@GET
public Response getInfo(@QueryParam("name") final String name){
...
}

//method 2
@GET
public Response getInfo(@QueryParam("name") final String name){
....
}

//method 3
@GET
public Response getInfo(@QueryParam("name") final String name, @Queryparam("age") final int age, @Queryparam("sex") final String sex){
....
}
}

我希望对于 url1,将调用方法 1,对于 url2,将调用方法 2,对于 url3,将调用方法 3。

但这不起作用。没有调用预期的方法。

请帮助我确定我在哪里做错了。

restlet version : 2.3.4

【问题讨论】:

    标签: java rest restlet


    【解决方案1】:

    JAX-RS 不允许有两个端点具有相同的 HTTP 路径和不同的查询参数。

    建议你通过-Two GET methods with different query parameters : REST

    【讨论】:

      猜你喜欢
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多