i have a use case where the user can send following params with get request
GET localhost/8080/users?filter=alex OR GET localhost/8080/users?suffixFilter=lex OR GET localhost/8080/users?prefixFilter=a
is it possible to add only one request param instead of 3 in controller
e.g.
instead of
@GetMapping("/users")
@ResponseBody
public String getFoos(@RequestParam String filter, @RequestParam String prefixFilter , @RequestParam String suffixFilter) {
return "ID: " + id;
}
is it possible to create a dynamic one which includes those three variantes? I was thinking creating class like this
public class FilterCreteria {
private String filter;
private String suffixFilter;
private String prefixFilter;
}
and then passing this to controller
@GetMapping("/users")
@ResponseBody
public String getFoos(@RequestParam FilterCreateria filter) {
return "ID: " + id;
}
the problem is if i send filter=alex the other attributes in the class FilterCreteria is null and i want to avoid this null.
What i searching for:
is there other way of making this possible? if my suggestion is ok, how to avoid null attributes when the user only sends one queryparam like filter=alex?