发送 GET 请求时无法将类型 'java.lang.String' 的值转换为所需类型 'java.util.Date'
Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' when sending GET request
我的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 和发件人值两边的单引号,这样看起来像这样
?beginPeriodDate=2019-08-25&request=false&requestNumber=2710100307142417&sender=27851024302531
我的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 和发件人值两边的单引号,这样看起来像这样
?beginPeriodDate=2019-08-25&request=false&requestNumber=2710100307142417&sender=27851024302531