I have a method in a spring controller
@GetMapping
public ResponseEntity<RetailerCandidateFormResponse> getRetailerCandidateForm(
@RequestParam String a, @RequestParam String b, @RequestParam String c) {
//Method body goes here
}
I want @Requestparam A a
to be mandatory which can be achieved by @Requestparam(required=true) A a
or by keeping it as it is as, this is a default behavior of @Requestparam
annotation.
But, what If I want to make either of @RequestParam String b
or @RequestParam String c
mandatory i.e. if @RequestParam String b
is present in request then @RequestParam String c
need not be present and vice versa but both cannot be null
a the same time. How can I achieve this at controller level?
Inside method body, I can write this if-else-if
logic and throw an exception if both the params are null
but, I don't want to do that.
@RequestParam(required=false)
for b and c`