如何在同一个请求中使用@Pathvariable 和@RequestParam
How to use @Pathvariable and @RequestParam at the same request
我正在尝试这段代码:
请求URL:获取:/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
一起使用。看看这些答案也是值得的。
我正在尝试这段代码:
请求URL:获取:/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
一起使用。看看这些答案也是值得的。