需要一个JPA查询来对过去4个小时发布的帖子进行排序

问题描述 投票:1回答:1

@存储库公共接口PostRepository扩展了JpaRepository {

Page<Post> findAllByCategory(Pageable pageable, Category category);


LocalDate dateBefore4Hours = LocalDate.now().minus(4, ChronoUnit.HOURS); //tried but couldnt figured it out


@Query("SELECT a FROM Post a WHERE a.createdDate  ") //none of sql keywords i've tried here didnt wor
Page<Post> findAllWithCreationDateTimeInLastFourHours();

}

java spring spring-boot jpa jpql
1个回答
0
投票

如果需要比较时间,可以使用LocalDateTime,因为LocalDate没有时间部分。因此,要获得4小时前的LocalDateTime,您可以执行以下操作:

© www.soinside.com 2019 - 2024. All rights reserved.