在两个日期之间获取数据

在两个日期之间获取数据

我的控制器映射

@GetMapping("/fetch/{one_date}/{two_date}")
public List<CourierInfo> getData_between(@PathVariable(value = "one_date") @DateTimeFormat(pattern = "yyyyMMdd") LocalDateTime fromDate, @PathVariable(value = "two_date") @DateTimeFormat(pattern = "yyyyMMdd") LocalDateTime toDate) {
    return bookRepository.getData_between(fromDate, toDate);
}


我的自定义查询

@Query(nativeQuery = true, value="select c.cons_no, c.pick_date, from CourierInfo c where c.pick_date between :startDate and :endDate")


列表getData_between(@Param(“ startDate”)LocalDateTime date,@Param(“ endDate”)LocalDateTime date2);

我在过去

http://localhost:8080/book_api/fetch/2020-01-20/2020-01-20


在这里,我试图在两个日期之间获取数据。
我收到此错误

Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.PathVariable @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime] for value '"2020-01-20"'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value ["2020-01-20"]

最佳答案

检查此主题:
https://stackoverflow.com/a/53188501/4135813

该问题与端点配置中缺少转换器有关

关于java - 如何在两个日期之间获取数据REST Spring,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59877635/

10-10 11:55