【发布时间】:2020-01-23 11:34:24
【问题描述】:
我的控制器映射
@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")
List 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"]
【问题讨论】:
-
20200120 是一个字符串,你需要一个日期
-
已于 2020 年 1 月 20 日尝试。不工作
标签: java rest spring-boot