Paging query needs to have a pageable parameter [Spring Boot]

Viewed 1887

I'm new to spring boot. I've tried to solve this bug for a whole afternoon but haven't get it right. I've checked these sites and tried to solve in their way but still failed. :Issue of pagination in Spring Data JPA https://www.logicbig.com/tutorials/spring-framework/spring-data/pagination.html https://blog.csdn.net/weixin_42050545/article/details/84317816

My situation here is that I want to GET the data from my database on the browser. There are many data, and I want to separate the data by page. Every page only has 3 data. And when I pass the page number through browser, for example, http:localhost:8080/test?page=1, I'll need to see the according data containing in the very page.

here is my Contoller :

//I have @autowired ExampleService here beforehand

@GetMapping("/test")
public Page<DatabaseTableName> getDataByPage(@RequestParam(value="page") int pageNum){
return exampleService.separatePage(pageNum);}

here is my Repository:

Page<DatabaseTableName> findAll(Pageable pageable);
List<DatabaseTableName> findAll(String id);

here is my ServiceImplementation class:

//I have @autowired ExampleRepository here beforehand

@Override
public Page<DatabaseTableName> separatePage(int pageNum){
return exampleRepository.findAll(PageRequest.of(pageNum, 3));

My error messages basically are :

Failed to load Application Context

error creating bean with name 'exampleRepository': FactoryBean threw exception on object creation; nested exception is java.lang.illegalargumentexception Paging query needs to have a pageable parameter! offending method public abstract org.springframework.data.domain.Page.com.practice.repo.ExampleRepository.findAll(java.awt.print.pageable)

I get confused with Paging query needs to have a pageable parameter don't exactly know how to assign the parameter, I've tried to add List<DatabaseTableName> findAll(String id) to Repository, and I thought it should solve the problem but it did not. Pls provide some guide. Thank you in advance!!!

0 Answers
Related