需要有关 JAX-RS 路径模板正则表达式的帮助

发布于 2024-10-19 06:40:40 字数 603 浏览 3 评论 0原文

我有一个 JAX-RS 服务,它可以与以下路径模板配合得很好:

@Path("/country/{countryIso:\\w{2}}")

来扩展它

@Path("/country/{countryIso:.+}")

但现在我想通过将其更改为Which will match any strings after "/country/" 。但我不知道如何将这些字符限制为我之前的正则表达式。我想强制为每个国家/地区 ISO 代码仅提供 2 个字符。

示例: http://localhost/myService/country/BR/MX - 应该有效

http://localhost/myService/country/BR/fred - 应该无效且不允许。

非常感谢任何帮助。 提前致谢。

I have a JAX-RS service that works very well with the following path template:

@Path("/country/{countryIso:\\w{2}}")

But now I want to expand on that by changing it to

@Path("/country/{countryIso:.+}")

Which will will match any stream of characters after "/country/". But I can't figure out how to restrict those characters to the regex that I had previously. I want to enforce that only 2 characters are provided for each country ISO code.

Examples:
http://localhost/myService/country/BR/MX - should be valid

http://localhost/myService/country/BR/fred - should be invalid and not allowed.

Any help is greatly appreciated.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木格 2024-10-26 06:40:40

您是否可以使用:

@Path("/country/{countryIso:\\w{2}(/\\w{2})*}")

这将匹配 BR、BR/MX、BR/MX/ad,但不匹配 BR/fred。

Could you perhaps use:

@Path("/country/{countryIso:\\w{2}(/\\w{2})*}")

That would match BR, BR/MX, BR/MX/ad but not BR/fred.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文