gpt4 book ai didi

java - RESTful 服务器中的@Path 正则表达式

转载 作者:行者123 更新时间:2023-11-30 09:57:14 25 4
gpt4 key购买 nike

我正在使用 CXF 框架编写 RESTful Java 服务器。

如何编写 @Path 正则表达式以获得任何以“/action”值结束的 URI?

最佳答案

不确定您想要的是 /action/*/*/action 还是 /*/action/*?不管怎样,这里是:

1)/action/*可以匹配到

@Path("/action/{search:.*}")<br>
doStuff(@PathParam("search") List<PathSegment> list)

在此示例中,GET/action/order/2/price 之类的请求将由 doStuff() 方法提供服务,其中 list 可用于获取正则表达式捕获的order/2/price中的所有路径段。

2)/*/action 可以匹配(警告未测试)

@Path("/{search:.*}/action")
findStuff(@PathParam("search") List<PathSegment> list)

在此示例中,GET/item/2/action 之类的请求将由 findStuff() 方法提供服务,其中 list 可以用于获取正则表达式捕获的item/2中的所有路径段。

3)/*/action/* 在这里,我相信你运气不好(如果我错了,请随时纠正我),有关更多信息,请查看此 blog发布。

关于java - RESTful 服务器中的@Path 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1920161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com