示例#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;
 }
示例#2
0
 public void save(Category category) {
   categoryRepository.save(category);
 }
示例#3
0
 public Category find(Long id) {
   return categoryRepository.findOne(id);
 }
示例#4
0
 public void delete(Long id) {
   categoryRepository.delete(id);
 }
示例#5
0
 public List<Category> findAll() {
   return (List<Category>) categoryRepository.findAll(new Sort(Direction.DESC, "id"));
 }
示例#6
0
 public List<Category> findTop3() {
   return categoryRepository
       .findAll(new PageRequest(0, 15, new Sort(Direction.DESC, "createDate")))
       .getContent();
 }