我有一个 Spring Controller 类,设置为 @RequestMapping("/vehicle")
设置在类(class)级别。该类的一种方法是
@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"
如果我颠倒 doAs
的顺序和registration
在 URL 中,错误显示 'doAs' is not present
.
如果我将该方法修改为仅采用一个参数( doAs
或 registration
),那么它就可以正常工作。
这里出了什么问题?我尝试过使用 param
在 @RequestMapping
但这也行不通。
最佳答案
您没有保护&符号免受外壳的影响,这就是为什么您还会得到其他奇怪的外壳输出。将 URL 放在引号中。
关于java - 使用 Spring MVC 处理多个 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34772502/