postgresql - 如何将 LocalDateTime 提供给 jpa/hibernate 查询?
问题描述
我正在我的@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);
推荐阅读
- android - 在矩形内绘制圆角
- android - 如何将谷歌地图上的交通数据解析为json?
- javascript - 地图 Js 中的逗号
- javascript - 如果在选择器中使用变量,则未正确选择子元素
- java - 找不到符号 [ERROR] 符号:方法 getlogger(java.lang.Class
) - sql - SAP HANA -count(*) 给出不同的输出
- c# - 如何使用 ASP.NET 和 C# 在 Gridview 中实现批量保存
- javascript - 如何使用 Jest 和 Enzyme 测试具有 Router、Redux 和两个 HOC 的 React 组件?
- javascript - Node.js child_process TypeError:无法读取未定义的属性“_writableState”
- php - 使用 array_intersect 检查数组中的多个值