title: How can I choose ideal way for pagination in Spring boot?
body: <p>I need your advice for paginations.</p>
  
  <p>My table data is very long.Therefor I use pagination and every pag action İ call data from database<br/>
  I have a rest method in spring-boot application.<br/>
  This method could get data from database and everthing is ok.<br/>
  I need pag count(all count of my data/ perPage count).<br/>
  I can find this count from db.<br/>
  I must write two seperate method for allCount and the below method?<br/></p>
  
  <p>How can I use ideal way for pagination in Spring boot?</p>
  
  <pre><code>  @CrossOrigin(maxAge = 3600)
      @RequestMapping(value = "/payment/all", method = RequestMethod.POST)
      public List&lt;NotaryPaymentInformationEntity&gt; getAllProduct(@RequestBody PaginationModel pag){
          try {
              System.out.println(pag.getPageno()+ " " + pag.getRecords());
              Thread.sleep(1000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          Pageable pageable = new PageRequest(pag.getPageno(), pag.getRecords());
          System.out.println("here"+notaryPaymentRepository.findAll(pageable).getContent().size());
          return notaryPaymentRepository.findAll(pageable).getContent();
      }
  
  
  
  
  public interface NotaryPaymentRepository  extends JpaRepository&lt;NotaryPaymentInformationEntity,Integer&gt;{
  
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KJ6VQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KJ6VQ.png" alt="enter image description here"></a></p>