我正在我的@RepositoryRestResource 中构建查询
查询看起来像这样:
@Query("Select DISTINCT comp from InsuranceCompany comp " +
"LEFT JOIN comp.orders ord " +
"wHERE ord.invoiced = false " +
"and (:date is null or :date >= ord.completionTime)"
)
public Page<InsuranceCompany> method(LocalDateTime date, Pageable pageable);
但是它抛出了下面的异常
Failed to convert from type [java.lang.String] to type [java.time.LocalDateTime] for value '2020-02-14T15:50:24'
当我调用终点时:
GET /method?date=2020-02-14T15:50:24
最佳答案
用 @DateTimeFormat
标记它让 Spring 正确转换它:
public Page<InsuranceCompany> method(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime date,
Pageable pageable);
关于postgresql - 如何向 jpa/hibernate 查询提供 LocalDateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60307870/