Issue
So all of this works fine, and in the browser / postman returns two Krytyks with a given name, but when i go to localhost:8080?/krytyk/getbyname/{name}/?page=2 it shows the same thing as on the default page, even though there should be different objects there. Same goes for all the other pages. Any suggestions?
Repo
public interface KrytykPageableRepository extends
JpaRepository<Krytyk, Long> {
@Query("select k from Krytyk k where k.name=:name")
Page<Krytyk> findKrytykByName(@Param("name") String name,
Pageable pageable);
}
Controller
@GetMapping(path = "/krytyk/getbyname/{name}")
public ResponseEntity<List<Krytyk>> GetByName(@PathVariable(name = "name") String name,
@RequestParam(defaultValue = "0") Integer
pageNo,
@RequestParam(defaultValue = "2") Integer
pageSize){
return ResponseEntity.ok(krytykService.findByImie(name, pageNo, pageSize));
}
Service
public List<Krytyk> findByImie(String name, Integer pageNo, Integer pageSize){
Pageable paging = PageRequest.of(pageNo, pageSize);
var paged = krytykPageableRepository.findKrytykByImie(name, paging);
return paged.hasContent() ? paged.getContent() : new ArrayList<>();
}
Solution
I would suggest adding the value
parameter to @RequestParam
like below:
//localhost:8080/krytyk/getbyname/{name}/?pageNo=2
@GetMapping(path = "/krytyk/getbyname/{name}")
public ResponseEntity<List<Krytyk>> GetByName(
@PathVariable(name = "name") String name,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize",defaultValue = "2") Integer pageSize){
return ResponseEntity.ok(krytykService.findByImie(name, pageNo, pageSize));
}
Answered By - Jasin Shala