@存储库公共接口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();
}
如果需要比较时间,可以使用LocalDateTime
,因为LocalDate
没有时间部分。因此,要获得4小时前的LocalDateTime
,您可以执行以下操作: