英文:
Spring path variable url
问题
我们有一个如下的请求映射
@RequestMapping(value = "/{city}/{category}", method = RequestMethod.GET)
现在 Spring Security OAuth 的 URL 也被定向到上述映射
"/oauth/token"
我该如何阻止这种情况,或者有任何建议让 "/{city}/{category}" 变得更加具体。
附注:"/resources/manifest.json" 也被定向到相同位置。
英文:
We have a request mapping as below
@RequestMapping(value = "/{city}/{category}", method = RequestMethod.GET)
Now spring security OAuth URL also get directed to the above mapping
"/oath/token"
How do I prevent this or Any suggestion to make "/{city}/{category}" more specific.
PS:- "/resources/manifest.json" is also getting directed to same.
答案1
得分: 1
我认为你应该更改你的命名约定,因为当你在路径中依次使用两个路径参数时,它就像两个通配符/**/,任何东西都可以匹配那个URL。
当你创建RESTful应用程序时,应该遵循REST命名约定。在你的情况下,应该是:
@RequestMapping(value = "cities/{cityId}/categories/{categoryId}", method = RequestMethod.GET)
REST命名约定解释:
https://restfulapi.net/resource-naming/
英文:
I think you should change you naming convention, because when you use two path parameters one by one in your path it's like two wildcards /*/* anything can match that URL.
When you create RESTful application you should follow the REST naming convention. In your case it should be:
@RequestMapping(value = "cities/{cityId}/categories/{categoryId}", method = RequestMethod.GET)
REST naming convention explained:
https://restfulapi.net/resource-naming/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论