JpaRepository有分页查询的函数,按API要求传递对应参数即可分页查询。

分页查询需要传入分页对象Pageable pageable = PageRequest.of(pageNum, pageSize);

关键代码如下:

//Repository
@Repository()
public interface ApplicationRepository extends JpaRepository<ApplicationDTO, Integer>{
    Page<ApplicationDTO> findAll(Pageable pageable);
}

//Service
@Service
public ApplicationService {
    @Autowired
    private ApplicationRepository applicationRepository;
    public Page<ApplicationDTO> getApps(Integer pageNum, Integer pageSize) {
        if(Objects.isNull(pageNum)){
            pageNum = 0;
        }
        if(Objects.isNull(pageSize)){
            pageSize = 10;
        }
        Pageable pageable = PageRequest.of(pageNum, pageSize);
        return applicationRepository.findAll(state,pageable);
    }
}

相关文章:

  • 2021-06-04
  • 2021-09-24
  • 2021-08-06
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2022-01-01
  • 2022-03-04
  • 2021-10-19
相关资源
相似解决方案