【发布时间】:2020-04-08 05:21:26
【问题描述】:
我正在尝试获取带有时间戳的用户的用户的所有数据:
@GetMapping("/datum/{userID}/{timeStamp}")
List<Datum> getDataSingleUserTimeRange(@PathVariable Long userID, @PathVariable LocalDateTime timeStamp)
{
....
}
现在为了测试这个 Spring Boot rest api,我在 postman 中调用了 GET 和 url - http://localhost:8080/datum/2/2019-12-15T19:37:15.330995。
但它给了我错误提示:无法将类型“java.lang.String”的值转换为所需类型“java.time.LocalDateTime”
我该如何解决这个问题??
【问题讨论】:
-
:是 URI 中的一个特殊字符。我会在这里使用时间戳而不是格式化的日期时间 -
您的变量名为
time。但是路径变量被命名为timeStamp。 -
@JBNizet 正确,但更正后,我收到此错误 - '无法将'java.lang.String'类型的值转换为所需类型'java.time.LocalDateTime'
-
@JBNizet 请参阅this question
标签: spring spring-boot spring-data-jpa spring-data