Advertisement
SimpleCookie

Untitled

Feb 20th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import org.springframework.beans.factory.annotation.Autowired;
  2. import org.springframework.stereotype.Service;
  3. import java.util.List;
  4.  
  5. @Service
  6. public class YourService {
  7.  
  8. @Autowired
  9. private YourEntityRepository yourEntityRepository;
  10.  
  11. public List<YourEntity> getFilteredEntities(Filter filter) {
  12. // Create an example instance using the provided filter
  13. YourEntity exampleEntity = new YourEntity();
  14. exampleEntity.setNamn(filter.getNamn()); // Set the 'namn' field
  15. exampleEntity.setBolag(filter.getBolag()); // Set the 'bolag' field
  16.  
  17. // Create a matcher for the Example instance
  18. ExampleMatcher matcher = ExampleMatcher.matching()
  19. .withIgnoreNullValues()
  20. .withIgnoreCase()
  21. .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); // Use appropriate matching strategy
  22.  
  23. // Create the Example object
  24. Example<YourEntity> example = Example.of(exampleEntity, matcher);
  25.  
  26. // Use the repository method to find matching entities
  27. return yourEntityRepository.findAll(example);
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement