title: Spring Boot Data JPA Paging implementing in correct way
body: <p>I want to add Paging functionality in Spring Boot + Spring Data JPA App, I have <code>Repository</code> :</p>
  
  <pre><code>@Repository
  public interface PostRepository extends JpaRepository&lt;Post, Long&gt; {
      List&lt;Post&gt; findAllByOrderByPostIdDesc(Pageable pageable);
  }
  </code></pre>
  
  <p>and in <code>Service</code> class I have :</p>
  
  <pre><code>@Service
  public class PostService {
  
      @Autowired
      private PostRepository postRepository;
  
      public List&lt;Post&gt; findAll(Pageable pageable) {
          return postRepository.findAllByOrderByPostIdDesc(pageable);
      }
  }
  </code></pre>
  
  <p>in the end <code>Controller</code> is </p>
  
  <pre><code>@Controller
  public class HomeController {
  
      @Autowired
      private PostService postService;
  
      @GetMapping(value = "/")
      public String getHomePage(Model model, Pageable pageable){
          model.addAttribute("postList", postService.findAll(pageable));
          return "home";
      }
  }
  </code></pre>
  
  <p>the code above on <code>http://localhost:8080</code> mapping I get all the records as response, but if I pass <code>page</code> and <code>size</code> params as <code>http://localhost:8080/?page=0&amp;size=1</code> I get paging working.</p>
  
  <p>Now I want to make <code>http://localhost:8080/?page=0&amp;size=1</code> by default landing page address, and in HTML code how can I dynamically update values of params <code>page</code> and <code>size</code> which is : </p>
  
  <pre><code> &lt;ul class="pagination justify-content-center mb-4"&gt;
              &lt;li class="page-item"&gt;
                &lt;a class="page-link" th:href="@{/(page=0,size=1)}"&gt;&amp;larr; Older&lt;/a&gt;
              &lt;/li&gt;
              &lt;li class="page-item disabled"&gt;
                &lt;a class="page-link" th:href="@{/(page=0,size=1)}"&gt;Newer &amp;rarr;&lt;/a&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
  </code></pre>
  
  <p>I have tried a many tricks but none worked for me!!</p>
  
  <h2>Update</h2>
  
  <p>I tried and added this class as suggested but @Nyle Hassan,</p>
  
  <pre><code>@Configuration
  public class DefaultView extends WebMvcConfigurerAdapter {
  
      @Override
      public void addViewControllers( ViewControllerRegistry registry ) {
          registry.addViewController( "/" ).setViewName( "forward:/?page=0&amp;size=10" );
          registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
          super.addViewControllers( registry );
      }
  }
  </code></pre>
  
  <p>it resulted in :</p>
  
  <pre><code>2019-01-01 17:26:43.484 ERROR 3824 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] threw exception
  
  java.lang.StackOverflowError: null
      at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:597) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:597) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:597) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:597) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
      at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:597) ~[tomcat-embed-core-8.5.29.jar:8.5.29]
  </code></pre>