diff --git a/src/main/java/com/kert/controller/PostController.java b/src/main/java/com/kert/controller/PostController.java index 6b81ad8..58155c5 100644 --- a/src/main/java/com/kert/controller/PostController.java +++ b/src/main/java/com/kert/controller/PostController.java @@ -27,7 +27,7 @@ public ResponseEntity> getPosts( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) { - Page posts = postService.searchPosts(search, page, size); + Page posts = postService.searchPosts(search, page -1, size); return ResponseEntity.ok(posts); } diff --git a/src/main/java/com/kert/service/PostService.java b/src/main/java/com/kert/service/PostService.java index 8430799..038a326 100644 --- a/src/main/java/com/kert/service/PostService.java +++ b/src/main/java/com/kert/service/PostService.java @@ -41,7 +41,7 @@ private String extractTokenFromRequest(HttpServletRequest request) { public Page searchPosts(String search, int page, int size) { Pageable pageable = PageRequest.of(page, size); - if (search != null && !search.isEmpty()) { + if (search != null && !search.trim().isEmpty()) { return postRepository.findByTitleContainingOrTagContaining(search, search, pageable); } else { return postRepository.findAll(pageable);