Java Spring REST所有捕获的子URL。

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

Java Spring REST all catch sub-urls

问题

以下是您要翻译的内容:

有人知道用Java Spring REST捕获子URL的好方法吗?

例如,我有以下URL:

http://example.com/hauses/toll/country/usa?...

http://example.com/hauses/small/country/germany?...

http://example.com/hauses/underground/country/norway?...

...

其中一个的解决方案可能是这样的:

@RestController
@RequestMapping("/hauses/underground/country")
public class ProxyController {

    @GetMapping("/norway")
    public String readSalesOrder(HttpServletRequest request) {
          // 一些代码
    }
}

但我需要捕获"/hauses"后面的所有内容。类似这样的方式:

@RequestMapping("/hauses/*")

有人知道这个问题的解决方案吗?

非常感谢任何帮助!

英文:

Does someone know a good solution to catch sub URLs with Java Spring REST?

For example, I have urls:

http://example.com/hauses/toll/country/usa?...

http://example.com/hauses/small/country/germany?...

http://example.com/hauses/underground/country/norway?...

...

Solution for one of them will be something like this:

@RestController
@RequestMapping("/hauses/underground/country")
public class ProxyController {

    @GetMapping("/norway")
    public String readSalesOrder(HttpServletRequest request) {
          some code
    }
}

But I need to catch everything that after "/hauses". Something like this:

@RequestMapping("/hauses/*")

Does someone know solution for this?

Thanks a lot for any help!

答案1

得分: 1

@RequestMapping("/hauses/**") 可能会有帮助

链接:https://docs.spring.io/spring-framework/docs/3.1.0.RELEASE/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex

英文:

@RequestMapping("/hauses/**") may help

https://docs.spring.io/spring-framework/docs/3.1.0.RELEASE/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates-regex

huangapple
  • 本文由 发表于 2020年9月25日 19:28:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/64063268.html
匿名

发表评论

匿名网友

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

确定