0

I'm trying this code:

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) {

But it's not working. What am I doing wrong?

Aline
  • 3
  • 1

1 Answers1

0

Remove the ?model={model} part. It is not needed. If you leave it in the path you won't be able to call this API method.

Also i'm not sure if you can bind a @RequestParam to a list. You should use @MatrixVariable for that.

EDIT: According to the answerers in the SO thread Binding a list in @RequestParam it is possible to use List with @RequestParam. It can be worthwhile to take a look at those answers as well.

Maurice
  • 6,698
  • 9
  • 47
  • 104
  • Thanks! @Maurice – Aline Feb 01 '22 at 23:08
  • @Aline please also check [this SO thread](https://stackoverflow.com/questions/4596351/binding-a-list-in-requestparam) about binding a list in requestparam. According to the answerers it is possible to bind a list to requestparam. – Maurice Feb 01 '22 at 23:12
  • @Maurice, I think if you try to use `@MatrixVariable` it won't work, because spring has by default disabled the semicolon separation. You might need to follow this article https://www.baeldung.com/spring-mvc-matrix-variables#configuration – stergipe Feb 02 '22 at 11:17
  • 1
    @stergipe you can use `@MatrixVariable` with comma as well. – Maurice Feb 02 '22 at 17:27