泽西岛(JAX-RS)如何使用多个可选参数映射路径 [英] Jersey (JAX-RS) how to map path with multiple optional parameters
问题描述
我需要将带有多个可选参数的路径映射到我的端点
I need to map path with multiple optional arguments to my endpoint
路径类似于localhost/func1/1/2/3
或localhost/func1/1
或localhost/func1/1/2
,并且该路径应与
path will look like localhost/func1/1/2/3
or localhost/func1/1
or localhost/func1/1/2
and this path should be correctly matched with
public Double func1(int p1, int p2, int p3){
...
}
public Double func1(int p1, int p2, int p3){
...
}
我应该在注释中使用什么?
What should I use in my annotations?
与Jersey一起玩是一项测试任务,以找到一种使用多个可选参数的方法,而不是学习REST设计.
It's test task to play with Jersey to find a way for using multiple optional params, not to learn REST design.
推荐答案
要解决此问题,您需要将参数设为可选,但/
sign可选
To solve this you need to make your params optional, but also /
sign optional
最终结果将类似于以下内容:
In the final result it will looks similar to this:
@Path("func1/{first: ((\+|-)?\d+)?}{n:/?}{second:((\+|-)?\d+)?}{p:/?}{third:((\+|-)?\d+)?}")
public String func1(@PathParam("first") int first, @PathParam("second") int second, @PathParam("third") int third) {
...
}
这篇关于泽西岛(JAX-RS)如何使用多个可选参数映射路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!