I have the following metod in my @Restcontroller:
@GetMapping
public List<User> getByParameterOrAll(
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "phone", required = false) String phone) {
List<User> userList;
if ((email != null && !email.isEmpty()) && (phone == null || phone.isEmpty())) {
userList = super.getByEmail(email);
} else if ((email == null || email.isEmpty()) && (phone != null)) {
userList = super.getByPhone(phone);
} else {
userList = super.getAll();
}
return userList;
}
This method allows to handle following GET-requests:
GET: /customers/
GET: /customers?email=emai@email.com
GET: /customers?phone=8-812-872-23-34
But if necessary to add some more parameters for request. If it will be 10 or... 20 params,body of above method arrise outrageously! If there any way to pass value of @RequestParam to the method-body, I could realize, for example:
@GetMapping
public List<User> getByParameterOrAll(
@RequestParam(value = "any", required = false) String any) {
if (value=="email") {
userList = super.getByEmail(email);
} else if (value=="email") {
userList = super.getByPhone(email);
} else if .....
}
Is there any way to use @RequestParam-value in method-body?