按日期查询(数据库中的预言机日期和 java 实体中的本地日期)在 Spring Java 中不起作用



>我正在尝试在 spring 存储库类中按日期查询,但它不起作用。它在本地h2数据库上工作正常,但不适用于Oracle数据库。

在控制器类中:-

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<OrderLine>> getOrderDetails(@RequestParam("headerSummaryId") Long headerSummaryId,
        @RequestParam(value = "eventMonth",
                required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate eventMonth) {
    List<OrderLine> od = orderLineService.getOrderDetails(headerSummaryId, Optional.ofNullable(eventMonth));
    return ResponseEntity.ok().body(od);
 }

在服务等级:-

@Override
public List<OrderLine> getOrderDetails(Long headerSummaryId, Optional<LocalDate> eventMonth) {
    List<OrderLine> olList = new ArrayList<>();
        olList = orderLineSummaryRepo.findByHeaderSummaryIdAndEventMonthAndVisibleFlag(headerSummaryId,
                eventMonth.get(), true);
                return olList;
 }

在存储库类中:-

List<OrderLine> findByHeaderSummaryIdAndEventMonthAndVisibleFlag(Long headerSummaryId, LocalDate eventMonth,
        Boolean visibleFlag);

实体类中事件月份的日期类型为"本地日期"。我使用了org.eclipse.persistence.jpa版本2.6.4。

通过将Jsr310JpaConverters.class作为基包类添加到 EntityScan 注释中来注册

例如

@EntityScan(
        basePackageClasses = {YourAppplication.class, Jsr310JpaConverters.class}
)

最新更新