2017-05-05 51 views
0

我使用Spring框架,並在下面的倉庫currentOrder方法我發送日期作爲參數,但是當我做這個Parameter with that position [1] did not exist拋出異常 我發送以下網址 http://localhost:3000/api/orders/search/currentOrder?fromDate=2017-04-28&toDate=2017-05-02春:參數與位置不存在例外

我的代碼中的錯誤在哪裏?

public interface OrderRepository extends JpaRepository<Order, Long> { 
    @PreAuthorize("hasAuthority('rights')") 
    @Query("Select o.orderDate from Order o where o.orderDate between fromDate and toDate") 
    List<Order> currentOrder(@Param("fromDate") Date fromDate,@Param("toDate") Date toDate); 
} 

回答

1

您的參數未在查詢中使用。嘗試,而不是由:paramName

@Query("Select o.orderDate from Order o where o.orderDate between :fromDate and :toDate") 
List<Order> currentOrder(@Param("fromDate") Date fromDate,@Param("toDate") Date toDate); 

也可以引用?#{fromDate}here

+0

它工作的提及他們:「d 感謝:'))))) – SFAH

+0

歡迎您然後接受的答案是正確的) – StanislavL

+0

當定時器關閉,我肯定接受答案 – SFAH