“Spring路径变量URL”

huangapple go评论150阅读模式
英文:

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/

huangapple
  • 本文由 发表于 2020年5月30日 16:06:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/62099565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定