【问题标题】:How to use ".." to pass URL parameters into Jersey?如何使用“..”将 URL 参数传递到 Jersey?
【发布时间】:2014-10-27 23:05:32
【问题描述】:

我遇到过这个 URL RESTful 查询:

http://rest.ensembl.org/map/cdna/ENST00000288602/100..300?content-type=application/json

其中 100..300 是表示“从 100 到 300”(索引)的参数。我可以随意更改这些参数。

我也想在我的网络服务中传递这种查询参数。如何在 Jersey API 中对此进行注释,以及如何获取参数值?

【问题讨论】:

  • 为什么不直接将参数作为 100-300 传递,然后像 string.split("-") 那样解析请求。然后将 min 100 和 max 300 转换为 int 并创建一个从 100 到 300 的元素数组。

标签: java rest jersey


【解决方案1】:

您可以使用@Path 注解来映射 100..300 种 URL。

例如,下面的代码对我来说很好。

@Path("/Test")
@Component
public class TestRestfulService {
        @GET
        @Path("/100..200")
        @Produces(MediaType.APPLICATION_JSON)
        public String getText(){
            return "Success";
        }
}

使用上面的代码,你可以通过 localhost:8080/test/100..200 访问方法。

希望这能解决问题!

【讨论】:

    猜你喜欢
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    相关资源
    最近更新 更多