I'm not sure why this answer was so hard to find, so I'm posting it clearly here. Using Spring Boot REST for a GET
request, I just wanted to be able to encapsulate many RequestParam
s into a single object. So instead of something like this...
@RequestMapping(value = "/users", method = RequestMethod.GET)
List<User> getUsers(@RequestParam String firstName, @RequestParam String lastName);
...I wanted to encapsulate all of those filter params into a class like this:
public class Filters {
private String firstName;
private String lastName;
... more properties and then getters and setters
}
What tripped me up was that there were a bunch of posts that were saying that you should use dot notation, so like /foo?filters.firstName=Ben
, but for me at least, this did not work.
Instead, the simplest solution was to just remove the @RequestParam
altogether:
@RequestMapping(value = "/users", method = RequestMethod.GET)
List<User> getUsers(Filters filters);
And that was it. Spring magic for the win!