27. 페이지네이션v5

송민경's avatar
Mar 18, 2024
27. 페이지네이션v5

  • findAll_paging_test()하기 : 페이지네이션
package shop.mtcoding.blog.User; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import shop.mtcoding.blog.user.User; import shop.mtcoding.blog.user.UserJPARepository; import java.util.Optional; @DataJpaTest // import 안해도 IoC에 띄워줌 public class UserJPARepositoryTest { @Autowired private UserJPARepository userJPARepository; @Test public void findAll_paging_test() throws JsonProcessingException { // given Sort sort = Sort.by(Sort.Direction.DESC, "id"); Pageable pageable = PageRequest.of(0, 3, sort); // when Page<User> userPG= userJPARepository.findAll(pageable); // then ObjectMapper om = new ObjectMapper(); // json으로 변경 String json = om.writeValueAsString(userPG); System.out.println(json); } }
notion image
  • shift + N : 선택
  • JSON View 사이트
notion image
notion image
 
notion image
```
Share article
RSSPowered by inblog