Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- @Service
- public class YourService {
- @Autowired
- private YourEntityRepository yourEntityRepository;
- public List<YourEntity> getFilteredEntities(Filter filter) {
- // Create an example instance using the provided filter
- YourEntity exampleEntity = new YourEntity();
- exampleEntity.setNamn(filter.getNamn()); // Set the 'namn' field
- exampleEntity.setBolag(filter.getBolag()); // Set the 'bolag' field
- // Create a matcher for the Example instance
- ExampleMatcher matcher = ExampleMatcher.matching()
- .withIgnoreNullValues()
- .withIgnoreCase()
- .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING); // Use appropriate matching strategy
- // Create the Example object
- Example<YourEntity> example = Example.of(exampleEntity, matcher);
- // Use the repository method to find matching entities
- return yourEntityRepository.findAll(example);
- }
- }
Add Comment
Please, Sign In to add comment