gpt4 book ai didi

postgresql - 如何向 jpa/hibernate 查询提供 LocalDateTime?

转载 作者:行者123 更新时间:2023-12-03 11:20:53 26 4
gpt4 key购买 nike

我正在我的@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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com