gpt4 book ai didi

java - 发送 GET 请求时无法将类型 'java.lang.String' 的值转换为所需类型 'java.util.Date'

转载 作者:行者123 更新时间:2023-11-30 10:01:04 31 4
gpt4 key购买 nike

我的 Controller 中有这个方法(这是一个 Kotlin 方法,但我想你可以理解它):

open fun getAis(
@RequestParam("beginPeriodDate") @DateTimeFormat(pattern = "yyyy-MM-dd") beginPeriodDate: Date,
@RequestParam("request") request: Boolean,
@RequestParam("requestNumber") requestNumber: String,
@RequestParam("sender") sender: String
): Data =
service.get(beginPeriodDate, request, requestNumber, sender)

我正在尝试通过浏览器访问它。我发送这个:http://localhost:8097/shep/sync/ais?beginPeriodDate=2019-08-25?request=false?requestNumber=272710100307142417?sender=2727851024302531

得到这个:

Failed to convert value of type 'java.lang.String' to required type 
'java.util.Date'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type [java.lang.String] to type
[@org.springframework.web.bind.annotation.RequestParam
@org.springframework.format.annotation.DateTimeFormat java.util.Date] for
value '2019-08-25?request=false?requestNumber='2710100307142417'?
sender='27851024302531''; nested exception is
java.lang.IllegalArgumentException: Invalid format: "2019-08-25?
request=false?requestNumber='27..." is malformed at "?request=false?
requestNumber='27..."

最佳答案

似乎您的请求 URI 格式不正确& 分隔参数,而不是 ?。换句话说,你需要的是

?beginPeriodDate=2019-08-25&request=false&requestNumber='2710100307142417'&sender='27851024302531' 

此外,如果没有特别的理由,我会去掉 requestNumber 和 sender 值周围的单引号,这将使它看起来像这样

?beginPeriodDate=2019-08-25&request=false&requestNumber=2710100307142417&sender=27851024302531

关于java - 发送 GET 请求时无法将类型 'java.lang.String' 的值转换为所需类型 'java.util.Date',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57654103/

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