Spring Data JPA-具有"@Param日期"的自定义@Query;不起作用 [英] Spring Data JPA - custom @Query with "@Param Date" doesn't work

查看:319
本文介绍了Spring Data JPA-具有"@Param日期"的自定义@Query;不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自定义查询以按 Date 获取发票数据,但返回了 null .我确定我为数据库中存在的查询设置了完全相同的日期.

I create custom query for getting Invoice data by Date, but it returns null. I'm sure that I set exactly the same Date for query that exists in database.

我使用自定义查询,因为我想编写更多高级查询.但是在这个简单的查询中存在问题.这是我的示例代码:

I use custom query because I want more advance query to write. But issue exist in this simple query. Here is my sample code:

@Query("select i from Invoice i where " +
        "i.expirationDate = :expDate")
Invoice findCompanyInvoiceByDate(@Param("expDate") Date expDate);

我尝试了此代码,但它也无法正常工作

I tried this code but it does not work also:

 Invoice findByExpirationDate(Date expirationDate);

我还尝试在Date和@Param之前添加@Temporal(TemporalType.DATE),但结果为空.

I also tried to add @Temporal(TemporalType.DATE) before Date and @Param but result is null.

推荐答案

我只是将日期用作字符串,并使用了nativeQuery = true.对我来说效果很好.

I just used the date as a String and used nativeQuery = true. It worked well for me.

@Query(value ="select * from table st where st.created_date >= ?1", nativeQuery = true)
    List<YourObject> findAllByCreatedDate(@Param("createdDate") @DateTimeFormat(iso = ISO.DATE) String createdDate);

这篇关于Spring Data JPA-具有"@Param日期"的自定义@Query;不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆