gpt4 book ai didi

java - 如何在对 Spring Boot Controller 的 GET 请求中接受 LocalDateTime 参数?

转载 作者:搜寻专家 更新时间:2023-10-31 20:00:08 25 4
gpt4 key购买 nike

这个问题与this SO problem非常相似适用于较早的 Date API。

我想用 Java 8 LocalDateTime API 实现同样的效果。当我这样做时,

@RequestMapping("/locationSnapshot/{userId}/{pointInTime}")
public MyResponse getLocationInTime(
@PathParam(value="userId") Long userId,
@PathParam(value="pointInTime")
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss") LocalDateTime pointInTime) {

MyResponse response = new MyResponse();
return response;
}

我明白了,

Failed to instantiate [java.time.LocalDateTime]: No default constructor
found; nested exception is java.lang.NoSuchMethodException:
java.time.LocalDateTime.<init>()

最佳答案

使用@PathVariable 代替@PathParam

@RequestMapping("/locationSnapshot/{userId}/{pointInTime}")
public MyResponse getLocationInTime(
@PathVariable(value="userId") Long userId,
@PathVariable(value="pointInTime")
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss") LocalDateTime pointInTime) {

MyResponse response = new MyResponse();
return response;
}

关于java - 如何在对 Spring Boot Controller 的 GET 请求中接受 LocalDateTime 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43780997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com