简体   繁体   English

同一个 Jersey REST API 类的多个根路径

[英]Multiple root paths for same Jersey REST API class

I have a Jersey REST API class with following root path我有一个带有以下根路径的 Jersey REST API 类

@Path(/v1/{start}/resource)
public class classA{

//Business logic

}

Now I have a requirement where I need to have one more path which points to same REST class, ie have two paths pointing to same rest class, for example:现在我有一个要求,我需要多一个指向同一个 REST 类的路径,即有两个指向同一个 REST 类的路径,例如:

Both endpoints /v1/start/resource and /start/resource should hit the same above given rest class.两个端点/v1/start/resource/start/resource都应该与上面给定的休息类相同。

Is there any way to achieve this?有什么办法可以做到这一点?

Okay, I found a solution for this using Regx in the @Path annotation as follows:好的,我在 @Path 注释中使用 Regx 找到了一个解决方案,如下所示:

@Path("/{ver : (v1/)?}{start}/resource")
public class classA{

//Business logic

}

The "/{ver : (v1/)?}{start}/resource" will resolve to both /v1/start/resource or /start/resource "/{ver : (v1/)?}{start}/resource"将解析为/v1/start/resource/start/resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM