0

I have two methods mapped with @GetMapping:

@GetMapping(path = "/**", produces = MediaType.APPLICATION_JSON_VALUE, params = "test")
public String getTest(@RequestParam("test") String test) {
          ...
}
@GetMapping(path = "/some/path", produces = MediaType.APPLICATION_JSON_VALUE)
public String getTest() {
          ...
}

Is it possible to request to endpoint /some/path?test=string be mapped to first method, and request to endpoint some/path be mapped to second method?

pera.coyote
  • 41
  • 1
  • 10

1 Answers1

1

If I understand your issue correctly, you could use !test as the value of params:

@GetMapping(path = "/some/path", 
            params = "!test",
            produces = MediaType.APPLICATION_JSON_VALUE)

Quoting the params documentation:

[...] Expressions can be negated by using the != operator, as in myParam!=myValue. [...] Finally, !myParam style expressions indicate that the specified parameter is not supposed to be present in the request.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359