You may also simply use a library like this one, which lets you build dynamic filters (supports logical operators, comparators, enums, dates, booleans, joins, functions, and much more): https://github.com/turkraft/spring-filter
You won't have to create any repository interface and you will be able to use the provided query builder in your client app directly.
Example query:
/search?filter= average(ratings) > 4.5 and brand.name in ('audi', 'land rover') and (year > 2018 or km < 50000) and color : 'white' and accidents is empty
Usage:
@GetMapping(value = "/search")
public List<Entity> search(@EntityFilter Specification<Entity> spec, Pageable page) {
return repo.findAll(spec, page);
}
Don't forget the dependency:
<dependency>
<groupId>com.turkraft</groupId>
<artifactId>spring-filter</artifactId>
<version>0.9.5</version>
</dependency>
You may also check rsql, although it's a bit outdated now https://github.com/jirutka/rsql-parser