我有一個在類級設置的@RequestMapping("/vehicle")
的Spring Controller類。這個類的一個方法是使用Spring MVC處理多個URL參數
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public Vehicle getVehicleByRegistration(
@RequestParam(value="doAs", required = true) String doAsUser,
@RequestParam(value="registration", required = true) String registration) throws IOException {
return vehicleController.getByIndex(registration, doAsUser);
}
,我發送查詢它像:
curl -iv localhost:8096/vehicle/?doAs=user®istration=ABC1234
執行時,我得到含有響應:
"exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'registration' is not present"
如果我扭轉在URL中的doAs
和registration
的順序然後錯誤說'doAs' is not present
。
如果我修改方法只接受一個參數(doAs
或registration
),那麼它工作正常。
這裏怎麼回事?我已經嘗試在@RequestMapping
中使用param
,但這也不起作用。
嘗試車輛後去除/: 捲曲-iv本地主機:8096 /車輛的DOA =用戶註冊= ABC1234 – Andonaeus