Exemplo n.º 1
0
 public Page<Category> findAll(final int pageNumber, final int pageSize, final Integer type) {
   PageRequest pageRequest =
       new PageRequest(pageNumber - 1, pageSize, new Sort(Direction.DESC, "id"));
   Specification<Category> spec =
       new Specification<Category>() {
         public Predicate toPredicate(
             Root<Category> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
           Predicate predicate = cb.conjunction();
           if (type != null) {
             predicate.getExpressions().add(cb.equal(root.get("type").as(Integer.class), type));
           }
           return predicate;
         }
       };
   Page<Category> result = (Page<Category>) categoryRepository.findAll(spec, pageRequest);
   return result;
 }
Exemplo n.º 2
0
 public void save(Category category) {
   categoryRepository.save(category);
 }
Exemplo n.º 3
0
 public Category find(Long id) {
   return categoryRepository.findOne(id);
 }
Exemplo n.º 4
0
 public void delete(Long id) {
   categoryRepository.delete(id);
 }
Exemplo n.º 5
0
 public List<Category> findAll() {
   return (List<Category>) categoryRepository.findAll(new Sort(Direction.DESC, "id"));
 }
Exemplo n.º 6
0
 public List<Category> findTop3() {
   return categoryRepository
       .findAll(new PageRequest(0, 15, new Sort(Direction.DESC, "createDate")))
       .getContent();
 }