为 Jersey JAX RS 定义重叠 @Path 值时出现问题
我有两个资源类
Pc.java - @Path("/pc")
Tag.java - @Path("/{entity:(pc|networks)?}/{id}/tags")
,因此第二个资源处理以“/tags”结尾的“/pc”或“/networks”url 分支。
但问题是我在 Tag.java 中的方法都没有被调用。我认为这是因为 Pc.java 配置为处理 /pc,因此所有调用都会重定向到该资源,并且 Tag.java 不会被调用,所以我收到 404 错误。
- 我可以通过将 /tag 更改为父路径并在其下包含 (pc/networks) 来处理此问题,但我不想这样做,因为它不适合我们项目中其余网址的样式。
- 我可以有两组方法 - 一组在 Pc.java 下处理“/pc”,另一组在 Network.java 下处理“/networks”,但这似乎是重复的代码...
有什么想法吗?
I have two resource classes
Pc.java - @Path("/pc")
Tag.java - @Path("/{entity:(pc|networks)?}/{id}/tags")
So the second resource handles a branch of '/pc' or '/networks' urls that end with '/tags'.
But the problem is none of my methods in Tag.java are getting called. I think this is because Pc.java is configured to handle /pc, so all calls get redirected to that resource and Tag.java doesn't get called, so i get a 404 error.
- I can handle this by changing /tag to be the parent path and having (pc/networks) under it, but I dont want to do that because it doesnt suit the style of the rest of the urls in our project.
- I can have two sets of methods - one set under Pc.java which handles '/pc' and another set under Network.java which handles '/networks', but this seems like duplicating code...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许标签的至少一部分应该是 子资源个人电脑?
Perhaps at least part of Tag should be a sub-resource of Pc?