> For the complete documentation index, see [llms.txt](https://nelmm.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nelmm.gitbook.io/til/spring/data/pageable.md).

# Pageable

페이징, 정렬을 하기 위해 스프링 데이터 JPA가 제공하는 인터페이스

```java
@GetMapping
    public ResponseEntity queryEvents(Pageable pageable, PagedResourcesAssembler<Event> assembler){
        Page<Event> page = this.eventRepository.findAll(pageable);
        var pagedResources = assembler.toModel(page, e-> new EventResource(e));
        pagedResources.add(new Link("/docs/index.html#resources-events#resources-events-list").withRel("profile"));
        return ResponseEntity.ok(pagedResources);
    }
```

위와 같이 Repository에서 find시에 Pageable을 변수를 넣어주면 Repository는 JPARepository를 상속받고 이는 PagingAndSortingRepository를 상속받고 있어 find에 pageable속성을 넣어 줄 수 있다.

그러면 쿼리문의 `page`,`size(default =20)`,`sort(필드며,정렬 기준(ASC/DESC)`속성으로 pagination할 수 있다.

## PagedResourcesAssembler

pagination을 수행 한 json데이터에 link를 삽입해주기위해 resource로 변환 해주는 클래스

내부적으로 RepresentationModelAssembler을 상속받고 있어 page한 데이터를 객체로 바꾸고 객체에 링크를 추가 해줄 수 있다.

```java
 var pagedResources = assembler.toModel(page, e-> new EventResource(e));
        pagedResources.add(new Link("/docs/index.html#resources-events#resources-events-list").withRel("profile"));
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://nelmm.gitbook.io/til/spring/data/pageable.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
