turkraft / springfilter

Dynamically filter JPA entities and Mongo collections with a user-friendly query syntax. Seamless integration with Spring APIs. Star to support the project! ⭐️
https://turkraft.com/springfilter
216 stars 35 forks source link

Possible to filter without Spring boot controller? #363

Closed avidbrit closed 7 months ago

avidbrit commented 7 months ago

My project is using Vaadin with spring data jpa but not using spring boot controllers. Is it possible to filter an entity without using a controller and the @Filter annotation? Something like Filter("name: 'ABC'") that returns a Specification?

torshid commented 7 months ago

Hi @avidbrit

Yes it is possible:

@Autowired
private FilterParser filterParser;

@Autowired
private FilterSpecificationConverter filterSpecificationConverter;

public List<Entity> search(String filter) {
  FilterNode node = filterParser.parse(filter);
  FilterSpecification<Entity> spec = filterSpecificationConverter.convert(node);
  return repository.findAll(spec);
}