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; }
public List<Category> findAll() { return (List<Category>) categoryRepository.findAll(new Sort(Direction.DESC, "id")); }
public List<Category> findTop3() { return categoryRepository .findAll(new PageRequest(0, 15, new Sort(Direction.DESC, "createDate"))) .getContent(); }