如何使用 Spring boot 和 JPA 查询上个月的数据



我试图获取上个月的文档编号数据,但没有得到。我做了什么:

private DataIndicated getDataBetween(String numberDocument) {
LocalDateTime start = LocalDate.now().atStartOfDay();
LocalDateTime end = LocalDate.now().atTime(LocalTime.MAX);
return repository.findByDocumentAndDataBetween(numberDocument, start, end);
}

存储库:

DataIndicated findByDocumentAndDataBetween(String numberDocument, LocalDateTime start, LocalDateTime end);

有人知道吗​​如何使此查询只获取上个月的单据号数据?

我使用的是Java 8和SpringBoot 2.5.8

谢谢!

如果类型为LocalDateTime的实体中的Data变量和您想要获取上个月的数据,那么这应该会起作用,您可以在存储库中使用:

List<DataIndicated> findAllByDocumentAndDataAfter(String numberDocument, LocalDateTime localDateTime);

并将此localDateTime作为参数传递到存储库:

LocalDateTime localDateTime = LocalDateTime.now().minusMonths(1);

最新更新