하나의 리포지토리로 JpaRepository, QueryDSL 기능 모두 사용할 수 있음.
네이밍 지켜야 함.
// ExRepository
public interface RevenueRepository extends JpaRepository<Revenue, Long>, RevenueRepositoryCustom {
}
// ExRepositoryCustom
public interface RevenueRepositoryCustom {
List<Revenue> findByDate(LocalDate date);
}
// ExRepositoryImpl
@Repository
@RequiredArgsConstructor
public class RevenueRepositoryImpl implements RevenueRepositoryCustom {
private final JPAQueryFactory query;
@Override
public List<Revenue> findByDate(LocalDate date) {
return query.select(revenue)
.from(revenue)
.where(revenue.date.year().eq(date.getYear()))
.where(revenue.date.month().eq(date.getMonthValue()))
.fetch();
}
}