top5 조회 로직 구현
- data JPA의 내장 기능 사용 Top5로 호출하면 limit5를 걸어서 조회해줌
public interface CafeRepository extends JpaRepository<Cafe, Long>{
List<Cafe> findTop5ByOrderByCreatedDateDesc();
}
service 로직
디비에서 받아온 List를 Cafe -> CafeListResponseDto로 필요한 데이터만 담아 클라이언트로 반환
List<Cafe> cafeList = cafeRepository.findTop5ByOrderByCreatedDateDesc();
List<CafeListResponseDto> cafeListResponseDtos = cafeList.stream()
.map(c -> new CafeListResponseDto(c))
.collect(Collectors.toList());
'프로그래밍 > JPA Project - sparta' 카테고리의 다른 글
타임리프 값 -> 자바스크립트에서 사용하기 (0) | 2022.07.10 |
---|---|
전체 조회 로직 구현 (페이징o) (0) | 2022.07.09 |
Post Method Refactoring - 카페 등록 api 리팩토링 (0) | 2022.07.06 |
Spring Security - 페이지, thymeleaf 접근 제한 (0) | 2022.07.04 |
S3 이미지 업로드, 삭제 (0) | 2022.06.29 |