【问题标题】:Spring : Parameter with that position did not exist exceptionSpring:具有该位置的参数不存在异常
【发布时间】:2017-10-03 14:54:15
【问题描述】:

我正在使用 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);
}

【问题讨论】:

    标签: java spring date jpa exception


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

    【讨论】:

    • 它有效:"D 谢谢 :')))))
    • 我可以再问你一个问题吗?
    猜你喜欢
    • 2016-09-11
    • 2019-03-06
    • 1970-01-01
    • 2015-11-22
    • 2018-07-05
    • 1970-01-01
    • 2015-03-12
    • 2017-03-22
    • 2017-07-29
    相关资源
    最近更新 更多