Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 데비안
- d
- resttemplate
- 스프링부트핵심가이드
- baeldung
- iterator
- 알파회계
- 선형대수
- 목록처리
- 티스토리 쿠키 삭제
- /etc/network/interfaces
- 코드로배우는스프링부트웹프로젝트
- 처음 만나는 AI 수학 with Python
- 이터레이터
- Kernighan의 C언어 프로그래밍
- 구멍가게코딩단
- 자료구조와 함께 배우는 알고리즘 입문
- network configuration
- 스프링 시큐리티
- 리눅스
- GIT
- ㅒ
- 서버설정
- 코드로배우는스프링웹프로젝트
- 네트워크 설정
- 페이징
- 처음 만나는 AI수학 with Python
- 자료구조와함께배우는알고리즘입문
- 친절한SQL튜닝
- 자바편
Archives
- Today
- Total
bright jazz music
[bootBoard] N:1(다대일) 연관관계: 11-4. JPQLQuery로 Page<Object[]> 처리 본문
Framework/Spring
[bootBoard] N:1(다대일) 연관관계: 11-4. JPQLQuery로 Page<Object[]> 처리
bright jazz music 2022. 10. 11. 09:02이전 포스팅에서 튜플 객체를 사용하여 여러 객체를 가져오는 것을 확인하였다.
이번 포스팅에서는 원하는 파라미터(Pageable)을 전송하고, Page<Object[]>를 만들어서 반환하는 것이다.
1. searchBoardRepository에 searchPage()를 설계
searchPage() 추가
- PageRequestDTO 자체를 파라미터로 처리하지 않는 이유는 DTO를 가능하면 Repository 영역에서 다루지 않기 위해서이다.
//SearchBoardRepository.java
package com.example.bootboard.repository.search;
import com.example.bootboard.entity.Board;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface SearchBoardRepository {
Board search1();
//Page<Object[]> 처리
Page<Object[]> searchPage(String type, String Keyword, Pageable pageable);
}
2. searchBoardRepositoryImpl에서 searchPage()구현
우선은 다른 기능 없이 로그부터 출력해 보자
//SearchBoardRepositoryImpl.java
import static com.example.bootboard.entity.QBoard.board;
@Log4j2
public class SearchBoardRepositoryImpl extends QuerydslRepositorySupport
implements SearchBoardRepository {
//생성자
public SearchBoardRepositoryImpl(){
super(Board.class); //여기서 super는 querydslRepositorySupport이다.
}
//...
@Override
public Page<Object[]> searchPage(String type, String Keyword, Pageable pageable) {
log.info("searchPage............................");
return null;
}
///...
}
4. 테스트
테스트 작업에는 '제목(t)'으로 '1'이라는 단어가 있는 데이터를 검색해 본다.
아직 구현된 내용이 없어서 단순 로그만 출력된다.
//BoardRepositoryTests.java
@SpringBootTest
public class BoardRepositoryTests {
@Autowired
private BoardRepository boardRepository;
//.....
@Test
public void testSearchPage(){
Pageable pageable = PageRequest.of(0, 10,
Sort.by("bno").descending());
Page<Object[]> result = boardRepository.searchPage("t", "1", pageable);
}
//.....
}
결과
콘솔로그
searchPage............................가 출력된느 것을 확인할 수 있다.
2022-10-11 22:30:13.252 INFO 5860 --- [ Test worker] c.e.b.repository.BoardRepositoryTests : Started BoardRepositoryTests in 3.924 seconds (JVM running for 5.402)
2022-10-11 22:30:13.396 INFO 5860 --- [ Test worker] c.e.b.r.s.SearchBoardRepositoryImpl : searchPage............................
2022-10-11 22:30:13.424 INFO 5860 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-10-11 22:30:13.426 INFO 5860 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-10-11 22:30:13.432 INFO 5860 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 20s
6 actionable tasks: 5 executed, 1 up-to-date
오후 10:30:13: Task execution finished ':test --tests "com.example.bootboard.repository.BoardRepositoryTests.testSearchPage"'.
'Framework > Spring' 카테고리의 다른 글
Comments