【发布时间】:2020-11-28 23:10:20
【问题描述】:
我正在尝试使用 Spring data JPA 进行查询,并带有以下查询。但我可以得到任何给定日期之间的归档输出。
@Query(value = "SELECT new com.xxx.DonationByUserTotal(d.club.name, d.club.id , d.club.logo, SUM(d.amount)) " +
"from Donation d where d.user.id=?1 and d.createdDate >= ?2 GROUP BY d.club")
List<DonationByUserTotal> findByUserAndFromDate(int User, @Param("fromDate") Date fromDate);
此查询返回给定用户的所有日期,但不在给定日期之间过滤。
@Query("SELECT new com.xxx.DonationByUserTotal(d.club.name, d.club.id , d.club.logo, SUM(d.amount) )" +
"from Donation d where d.user.id=?1 and d.createdDate BETWEEN ?2 and ?3 GROUP BY d.club")
List<DonationByUserTotal> findByUserAndBetweenDates(int User,@Param("from")Date fromDate,@Param("to") Date toDate);
尽管两者之间的日期有效,但此查询返回一个空集。
有人可以帮我解决这个问题吗?
PS:
实体类正在使用
@CreatedDate
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false, updatable = false)
private Date createdDate;
传递给查询的参数也带有时间戳。
【问题讨论】:
标签: java spring spring-boot spring-data-jpa spring-data