Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowed values for RequestParam in get url

Is it possible to set possible values for @RequestParam(value = "id") String id)
?

The ideal is: I give some List<String> allowedValues and it automatically validate it. (This list will be loaded from database).


1 Answers

use an enum instead of a String and define your enum values

@RequestMapping(value = "yourRestEndPoint", method = RequestMethod.GET)
public anyReturnType methodName(@RequestParam(defaultValue = "ONE") IdValue id) {
 ....
}

and have a separate class defined e.g

public enum IdValue {
  ONE, TWO, THREE
} 
like image 179
george Avatar answered Dec 13 '25 16:12

george



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!