xenteros xenteros - 1 month ago 7
Java Question

Rest endpoint mapped with @PathVariables separated by comma

I have

@RestController
with
@RequestMapping("/api/my-resource")
. I have
@GetMapping
for extracting certain entity.

@GetMapping(value = "/{firstId},{secondId}")
public ResponseEntity<MyResourceDTO> findMyResource(
@PathVariable Long firstId, @PathVariable String secondId) {

//here I have firstId == null and secondId == null
}


If I replace
,
with
/
everything works fine, but the requirement is not to use another
/
.

I can confirm, that I can enter this method, but both
@PathVariable
s are mapped to null. Does
Spring
support this kind of mapping? What have I done wrong?

I would like to achieve something similar to this, but I must use
Spring
.

Edit:

I have seen the solution with
List
but I don't want to use it, as the ids are of different type, so it's not a duplicate. I'm using
<spring.version>4.3.6.RELEASE</spring.version>

Answer Source

With your current Spring version, you can try using _ as the delimiter and it should work fine.

I read this once in a Spring Documentation, but can't find the link right now, will add it as soon as I find it.