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

标签 postgresql hibernate spring-boot jpa spring-data-rest

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

相关文章:

ruby-on-rails - 普通索引也可以通过创建唯一索引来工作吗?

java - 双向 jpa hibernate 关系 @OneToMany @ManyToOne 失败,因为未存储父 ID

hibernate - 将 H2 数据转换为 PostgreSQL

java - 在 Spring boot 中指定 Tomcat 'Resource's

spring - 必须在 Spring Boot 应用程序中设置 UserDetailsS​​ervice 错误

java - 如何正确地将图像从 servlet 传递到 JSP

sql - Postgresql 根据从文本列派生的排名选择结果

java - Spring中的线程命名

java - JPA (Hibernate) : "ORA-02289 Sequence does not exist", 但确实如此

java - 将 PostgreSQL JSON 列映射到 Hibernate 实体属性