아무거나

[JPQL] JPQL 기본 사용 예 본문

Java & Kotlin/JPA

[JPQL] JPQL 기본 사용 예

전봉근 2019. 8. 23. 13:13
반응형

[JPQL 사용]

Query annotation : Repository의 조회 메소드에 직접 실행될 쿼리를 작성

 

1. Controller.java

List<ProductLog> productLogs = productLogService.getProductLog(productLog, limit);

 

2. Service.java

List<ProductLog> getProductLog(ProductLog productLog, Integer limit);

 

3. ServiceImpl.java

@Override
public List<ProductLog> getProductLog(ProductLog productLog, Integer limit) {
	return repository.sqlFindWmpVendorIdAndDataProviderProcessType(productLog.getWmpVendorId(), productLog.getDataProviderProcessType(), productLog.getRegisterdTime(), limit);
}

 

4. Repository.java

@Repository
public interface ProductLogRepository extends CrudRepository<ProductLog, Integer> {
    @Query(value="SELECT * FROM categroy_product_logs WHERE wmp_vendor_id = :wmpVendorId AND data_provider_process_type = :dataProviderProcessType AND registerd_time = :registerdTime LIMIT :limit", nativeQuery = true)
    List<ProductLog> sqlFindWmpVendorIdAndDataProviderProcessType(
        @Param("wmpVendorId") String wmpVendorId,
        @Param("dataProviderProcessType") Integer dataProviderProcessType,
        @Param("registerdTime") Timestamp registerdTime,
        @Param("limit") Integer limit
    );
}
반응형
Comments