Insert v1 into @Path annotation (java 1.6)

问题: Our current path annotation omitted the 'v1' and we'd like to insert it. Since we cannot have more than one Path annotation, is there a way to add the v1 using a regular ex...

问题:

Our current path annotation omitted the 'v1' and we'd like to insert it. Since we cannot have more than one Path annotation, is there a way to add the v1 using a regular expression? I have seen this used for parameters, but not for constants in the endpoint.

So if my path annotation currently looks like this:

@Path("/rest/noun")

Can it be replaced with something like this?

@Path("/rest/noun|/rest/v1/noun")

Since some users are using the original path of /rest/noun, I want to offer the corrected one and the old one, not to break their current functionality. I want to offer both of these:

/rest/noun
/rest/v1/noun

回答1:

If you want more than one path for same code of execution, you can create wrapper function calling the current function internally like below:

@Path("/rest/noun")
void currentfunction(){
//all functionality code here
}

@Path("/rest/v1/noun")
void newfunction(){
currentfunction();
}

Or you can also use:

@Path("/rest/{parameter: v1\/noun|noun}")
void currentfunction(){
    //all functionality code here
    }
  • 发表于 2018-07-14 03:15
  • 阅读 ( 306 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除