【问题标题】:SpringBoot please suggest custom Query forSpring Boot请建议自定义查询
【发布时间】:2017-11-17 07:33:02
【问题描述】:

select * from ngb.subsidy where (有效开始日期,有效结束日期)重叠 ('2017-08-01'::DATE, '2017-08-01'::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] 的参数不存在

【问题讨论】:

    标签: spring-data-jpa


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      不要使用@Param("") 而不是使用?1

      例子

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-07
        • 1970-01-01
        • 2019-01-12
        • 2018-05-28
        • 2016-03-22
        • 1970-01-01
        • 1970-01-01
        • 2020-07-05
        相关资源
        最近更新 更多