I have a @RequestParam MultiValueMap<String, String> queryParams
. The controller takes queryParams from UI end to request JPA Repository and return records from the database.
Is there a way to directly send this MultiValueMap
to the repository interface and fetch records based on queryParams
?
I have a UserRepository
which extends JPARepository<User, Long>
.
The controller has a method which takes @RequestParam MultiValueMap<String, String> queryParams
as an input and needs to appropriately fetch records from the database and store it in a List<User>
.
Ex: if url = /api/users?name=USER123&salary=10000&department=science
I can neither use @PathVariable
because there are many such attributes in User which can be used for querying, nor have 1 method for each combination of queryParams
.
I need to send the queryParams
to fetch exact records matching the query parameters.
public ResponseEntity<List<User>> getSpecificUsers(
Pageable pageable,
@RequestParam MultiValueMap<String, String> queryParams
) {}
If there is a way to generate @Query
based on the RequestParam
query params I am open to use that as well. Any help is appreciated.