QueryDSL이슈-1

박상훈·2024년 3월 24일
0

개인공부

목록 보기
16/16

1. QueryDSL 적용 구문

@RequiredArgsConstructor
public class ReservationMonthInfoRepositoryQueryImpl implements ReservationMonthInfoRepositoryQuery{

  private final JPAQueryFactory jpaQueryFactory;


  @Override
  public List<ReservationMonthInfoResponseDto> reservationMonthInfoByStoreId(Long storeId) {
        List<ReservationMonthInfoResponseDto> result =
        jpaQueryFactory.select(
        Projections.bean(
            ReservationMonthInfoResponseDto.class
            ,reservationMonthInfo.yearInfo
            ,reservationMonthInfo.monthInfo
    ))
            .from(reservationMonthInfo)
            .where(reservationMonthInfo.store.id.eq(storeId))
            .fetch();

        for(ReservationMonthInfoResponseDto rs : result){
          System.out.println(rs.getYearInfo());
          System.out.println(rs.getMonthInfo());
        }
    return result;
  }
  • 적용 후 PostMan Test결과
  • 실제 데이터를 넣었음에도 null 값이 도출됐다.
      1. 빈 객체를 반환했디
      1. Dto 객체에 data를 set하지 못했다.

2. 결론

  • 2번의 문제였고, 해당 Dto에 set 프로퍼티 설정을 해주지 않아서, 데이터가 들어가지 않았다.
@Getter
@Setter // 요 부분
@NoArgsConstructor
public class ReservationMonthInfoResponseDto {

  private String yearInfo;
  private String monthInfo;
  ....}
profile
기록하는 습관

0개의 댓글