Advertisement
Guest User

repo

a guest
Jun 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. @Repository
  2. public class CustomItemRepositoryImpl implements CustomItemRepository {
  3.  
  4.     private final ItemRepository itemRepository;
  5.  
  6.  
  7.     @Autowired
  8.     public CustomItemRepositoryImpl(ItemRepository itemRepository) {
  9.         this.itemRepository = itemRepository;
  10.     }
  11.  
  12.  
  13.     @Override
  14.     public Page<Item> search(String name, String description, Collection<Long> categoryIds, Pageable pageable) {
  15.         ItemSpecificationBuilder builder = new ItemSpecificationBuilder();
  16.         Specification<Item> specs = builder
  17.                 .withNameLike(name)
  18.                 .withDescriptionLike(description)
  19.                 .withCategoriesIdsIn(categoryIds)
  20.                 .build();
  21.  
  22.         if (specs != null) {
  23.             return itemRepository.findAll(specs, pageable);
  24.         } else {
  25.             return itemRepository.findAll(pageable);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement