SpringBoot请建议自定义查询

时间:2017-11-17 07:33:02

标签: spring-data-jpa

从ngb.subsidy中选择* (effective_start_date,effective_end_date)OVERLAPS   (' 2017-08-01' :: DATE,' 2017-08-01' :: DATE)订单由effective_start_date asc

以下给定的查询无效

@Query(value="select * from ngb.security_deposit sd  where sd.consumer_no = :consumerNo and (sd.effective_start_date, sd.effective_end_date) OVERLAPS (:effectiveStartDate::DATE, :effectiveEndDate::DATE) order by sd.effective_start_date asc",nativeQuery=true)

public  List<SecurityDepositInterface> findByConsumerNoAndEffectiveStartDateAndEffectiveEndDate(@Param("consumerNo") String consumerNo, @Param("effectiveStartDate") Date effectiveStartDate, @Param("effectiveEndDate") Date effectiveEndDate);

表示 java.lang.IllegalArgumentException:具有该名称[effectiveStartDate]的参数不存在

2 个答案:

答案 0 :(得分:1)

在你的回购中

 @Query(value="select * from ngb.subsidy where (effective_start_date, effective_end_date) OVERLAPS ('2017-08-01'::DATE, '2017-08-01'::DATE) order by effective_start_date asc",nativeQuery=true)

 List<Your Entity class> = findbyID(); // any name

答案 1 :(得分:0)

请勿使用@Param("")代替?1

实施例

@Query(value="select * from table where colNO=?1 and colNO=?2",nativeQuery=true)
List<Your Entity class> = findbyID(String val1,String val2);