英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论