Issue
Spring allows for a given request mapping to specify parameters which must/must not be present or have a certain value. I was wondering if it is possible to assign multiple such parameter conditions to one request mapping like:
Either the parameter is not present or has a certain value.
@GetMapping(
path = ["/data"],
produces = [APPLICATION_JSON_UTF8_VALUE],
params = ["!allStates","allStates=false"]
)
fun getData(){[...]}
It looks like every condition derived from the params are logically linked via an AND. Additionally it seams like the second condition leads to an implied check for the existence of the parameter, which i do not want.
https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-ann-requestmapping-params-and-headers Is sadly not that specific.
Is there a way to manipulate these params conditions? Or am i better of defining multiple request mappings?
Solution
RequestMapping Javadoc is a bit more explicit here.
Note:
... a sequence of "myParam=myValue" style expressions, with a request only mapped if each such parameter is found to have the given value.
So you are right, the conditions are combined with logical AND, and thus separate mappings should be used.
Answered By - vladtkachuk
Answer Checked By - Clifford M. (JavaFixing Volunteer)