Spring Boot 当尝试将timestamp作为请求参数发送到我的rest API时,收到400

olqngx59  于 2023-04-30  发布在  Spring
关注(0)|答案(2)|浏览(203)

我试图通过postman向我的API发送时间戳请求参数,看起来像:

@GetMapping(path = "/get-data")
    public ResponseEntity<Response<Object>> getTaskStatusList(@RequestParam final Timestamp startDate, @RequestParam final Timestamp endDate){
 //Body

}

我的请求看起来像:

{{url}}/get-data?startDate=2018-06-27T19:32:21.158+0530&endDate=2018-06-27T19:32:21.158+0530

我得到了以下消息:

{
    "code": 400,
    "message": "Invalid value '2018-06-27T19:32:21.158 0530' of type 'String' for parameter 'startDate'. Type 'Timestamp' was expected."
}
xuo3flqw

xuo3flqw1#

您的时间戳格式错误。
根据this site和ISO-8601,您的时间戳应该是:

YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

在哪

YYYY = four-digit year
MM   = two-digit month (01=January, etc.)
DD   = two-digit day of month (01 through 31)
hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
mm   = two digits of minute (00 through 59)
ss   = two digits of second (00 through 59)
s    = one or more digits representing a decimal fraction of a second
TZD  = time zone designator (Z or +hh:mm or -hh:mm)

到时候可能会有用。

uyhoqukh

uyhoqukh2#

检查所有数据项的时间戳值,确保是法律的格式,而不是空值。

相关问题