![](/img/trans.png)
[英]How to use @Pathvariable and @RequestParam at the same time in Spring Rest
[英]How to use @Pathvariable and @RequestParam at the same request
我正在尝试这段代码:
请求 URL:GET:/produtName/v1/00000000123?model=1,2
@GetMapping(value="/{product}/{version}/{document}?model={model})
public ResponseEntity<String> test(
@PathVariable("product") String product,
@PathVariable("version") String version,
@PathVariable("document") String document,
@RequestParam("model") List<String> model) {
但它不起作用。 我究竟做错了什么?
删除?model={model}
部分。 它不是必需的。 如果您将其留在路径中,您将无法调用此 API 方法。
另外我不确定您是否可以将@RequestParam
绑定到列表。 您应该为此使用@MatrixVariable
。
编辑:根据 SO 线程Binding a list in @RequestParam 中的回答者,可以将List
与@RequestParam
一起使用。 看看这些答案也是值得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.