我正在尝试包括一个无效的请求param,但春季似乎将其作为强制性
控制器:
open fun calculate(@RequestHeader(name = USER_ID_HEADER, required = true) userId: String,
@RequestParam(name = "product_price_amount", required = true) productPriceAmount: BigDecimal,
@RequestParam(name = "product_price_currency", required = true) productPriceCurrency: String,
@RequestParam(name = "item_id", required = true) itemId: String,
@RequestParam(name = "promocode", required = true) promocode: String,
@RequestParam(value = "carrier_delivery_mode",
required = false, defaultValue = "BUYER_ADDRESS") carrierDeliveryMode: String? = "BUYER_ADDRESS"
获取请求
calculator/costs?product_price_amount=100&product_price_currency=EUR&item_id=g9kp615z5l32&promocode=1LL
我有以下错误:
[ { " error_code":"不良请求", "消息":"参数条件" product_price_amount,product_price_currency,item_id,promocode,carrier_delivery_mode "未满足实际请求参数:produck_price_amount = {100}" } ]
有什么想法为什么失败?
您已经在注释中具有默认值。请删除此?=" puyer_address"零件,只需将其保留carrierDeliverymode:string即可。希望很有帮助:(
我删除了@getMapping中的参数,它起作用了:(
@GetMapping("calculator/costs",
params = ["product_price_amount", "product_price_currency", "item_id", "promocode", "carrier_delivery_mode"])