Consider three REST resources:
/persons/id/{id}
/persons/code/{code}
/persons/email/{email}
I want to make one method in a Spring MVC
controller to handle these requests:
@RequestMapping("/persons/{searchField}/{searchValue}")
public Person search(@PathVariable field, @PathVariable value) {
...
}
The question: is there any elegant way to restrict searchField
's variable list of values on the annotation level except just by checking them in the method search
?
switch (field) {
case "id": ...
case "code": ...
...
default: // not found exception??
}
It can be easily done using regular expressions in the mapping:
@RequestMapping("/persons/{searchField:id|code|email}/{searchValue}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With