泽西岛(JAX-RS)如何使用多个可选参数映射路径 [英] Jersey (JAX-RS) how to map path with multiple optional parameters

查看:108
本文介绍了泽西岛(JAX-RS)如何使用多个可选参数映射路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将带有多个可选参数的路径映射到我的端点

I need to map path with multiple optional arguments to my endpoint

路径类似于localhost/func1/1/2/3localhost/func1/1localhost/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆