in

Trying to get pagination in my website Spring-boot


I tried to follow this tutorial to add pagination in my website.
https://www.javacodegeeks.com/2013/03/implement-bootstrap-pagination-with-spring-data-and-thymeleaf.html

But i get some errors

Caused by: java.lang.IllegalArgumentException: Paging query needs to have a Pageable parameter! Offending method public abstract org.springframework.data.domain.Page com.adminportal.repository.ShoesRepository.findByPublishedIsTrueOrderByPublishedTimeDesc(org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties$Pageable)

Here is my code

ShoesRepository.java

package com.adminportal.repository;

import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.CrudRepository;

import com.adminportal.domain.Shoes;

public interface ShoesRepository extends CrudRepository<Shoes, Long>{
    
    Page<Shoes> findByPublishedIsTrueOrderByPublishedTimeDesc(Pageable pageable);
    
}

ShoesService.java

package com.adminportal.service;


import java.util.List;

import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
import org.springframework.data.domain.Page;

import com.adminportal.domain.Shoes;



public interface ShoesService {
    Shoes save(Shoes shoes);
    
    List<Shoes> findAll();
    
    Shoes findOne(Long id);
    
    Page<Shoes> getAllPublishedPosts(Pageable pageable);
    
}

ShoesServiceImpl.java

package com.adminportal.service.impl;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import com.adminportal.domain.Shoes;
import com.adminportal.repository.ShoesRepository;
import com.adminportal.service.ShoesService;


@Service
public class ShoesServiceImpl implements ShoesService{

    
    @Autowired
    private ShoesRepository shoesRepository;
    
    public Shoes save(Shoes shoes) {
        return shoesRepository.save(shoes);
    }
    
    public List<Shoes> findAll() {
        return (List<Shoes>)shoesRepository.findAll();
    }

    @Override
    public Shoes findOne(Long id) {
        return shoesRepository.findById(id).orElse(null);
    }

    @Override
    public Page<Shoes> getAllPublishedPosts(Pageable pageable) {
        Page<Shoes> shoesList = shoesRepository.findByPublishedIsTrueOrderByPublishedTimeDesc(pageable);
        return shoesList;
    }

    
    
}

ShoesController.java

@RequestMapping(value = "/manageProducts", method = RequestMethod.GET)
    public String manageProductsGet(Model uiModel, Pageable pageable) {
        
        PageWrapper<Shoes> page = new PageWrapper<Shoes>
            (shoesService.getAllPublishedPosts(pageable), "/manageProducts");
        uiModel.addAttribute("page", page);
        return "manageProducts";
    }
    

manageProducts.html

 <div class="pages" th:fragment="paginationbar">
    <ul class="pagination">
    
    <li class="previous" th:class="${page.hasPrevious}? '' : 'disabled'">
        <span class="page-link" th:if="${not page.hasPrevious}">❮</span>
        <a class="page-link" th:if="${page.hasPrevious}" th:href="@{${page.url}(page.page=${page.number-1},page.size=${page.size})}" >❮</a>
      </li>
    
   <li th:each="item : ${page.items}' th:class="${item.current}? "active' : ''">
        <span class="page-link" th:if="${item.current}" th:text="${item.number}">1</span>
        <a class="page-link" th:if="${not item.current}" th:href="@{${page.url}(page.page=${item.number},page.size=${page.size})}"><span th:text="${item.number}">1</span></a>
      </li>
    
    <li th:each="item : ${page.items}' th:class="${item.current}? "active' : ''">
        <span class="page-link" th:if="${item.current}" th:text="${item.number}">2</span>
        <a class="page-link" th:if="${not item.current}" th:href="@{${page.url}(page.page=${item.number},page.size=${page.size})}"><span th:text="${item.number}">1</span></a>
      </li>
    <li th:each="item : ${page.items}' th:class="${item.current}? "active' : ''">
        <span class="page-link" th:if="${item.current}" th:text="${item.number}">3</span>
        <a class="page-link" th:if="${not item.current}" th:href="@{${page.url}(page.page=${item.number},page.size=${page.size})}"><span th:text="${item.number}">1</span></a>
      </li>
    
     
    <li class="nextpage" th:class="${page.hasNext}? '' : 'disabled'">
        <span class="page-link" th:if="${not page.hasNext}">❯</span>
        <a class="page-link" th:if="${page.hasNext}" th:href="@{${page.url}(page.page=${page.number+1},page.size=${page.size})}" title="Go to next page">❯</a>
      </li>
      
     
    </ul>
    
    
    
    </div>
  
 



Source: https://stackoverflow.com/questions/70559421/trying-to-get-pagination-in-my-website-spring-boot

Products API using Python Flask, SQL Alchemy and Marshmallow

Scanner Class with Delimiters Example in Java