DEV Community

Zaw Htut Win
Zaw Htut Win

Posted on • Edited on

Full Stack Development with Spring Boot (အခန်း ၈)

Custom Query

ဒီတစ်ခါတော့ Customer Entity နဲ့ Appointment Entity က ရှိပြီးသားလို့ ကျွန်တော် ယူဆပြီး custom query အကြောင်းရေးပါ့မယ်။

@Repository
public interface AppointmentRepository extends JpaRepository<Appointment, Long> {

    @Query("SELECT a FROM Appointment ‌a WHERE a.customer.id = :customerId AND a.appointmentTime BETWEEN :start AND :end")
    List<Appointment> findTodayCustomerAppointmentBetween(
        @Param("customerId") Long doctorId,
        @Param("start") LocalDateTime start,
        @Param("end") LocalDateTime end
    );
}
Enter fullscreen mode Exit fullscreen mode

ဒီနေရာမှာ :customerId ဆိုတဲ့ place holder ထဲကို

@Param("customerId")  က ဝင်မယ်။
Enter fullscreen mode Exit fullscreen mode
:start က @Param(start) 
:end က  @Param(end)  
Enter fullscreen mode Exit fullscreen mode

ဒါဆို ဒီနေ့ customer လာမယ့် appointment အချိန်၊ ညနေ သုံးနာရီကစပြီး ညနေ၅နာရီ ကို သိနိုင်မှာပါ။

Top comments (0)