검색 + Paging 처리

ims·2020년 11월 24일
0

BlueDot-Spring

목록 보기
13/13

참조사이트

https://victorydntmd.tistory.com/333

https://www.baeldung.com/spring-jpa-like-queries

UserRepository

@Repository
public interface UserRepository extends JpaRepository<User,Long> {
    List<User> findByName(String name, Pageable pageable);
}
  • Pageable을 parameter로 설정하면 page에 맞게 값을 받아올 수 있다.

UserController

@GetMapping("/name/pageable")
public List<UserApiResponse> pageableTest(@RequestParam String name,@PageableDefault(sort = "id",size = 10,direction = Sort.Direction.DESC) Pageable pageable){
    return userService.pageableTest(name,pageable);
}

@PageableDefault annotation을 통해 page의 sort,size등을 지정할 수 있다.

profile
티스토리로 이사했습니다! https://imsfromseoul.tistory.com/ + https://camel-man-ims.tistory.com/

0개의 댓글