gpt4 book ai didi

java - 使用 Spring MVC 处理多个 URL 参数

转载 作者:行者123 更新时间:2023-12-01 21:53:34 25 4
gpt4 key购买 nike

我有一个 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&registration=ABC1234

执行时,我收到包含以下内容的响应:

"exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'registration' is not present"

如果我颠倒 doAs 的顺序和registration在 URL 中,错误显示 'doAs' is not present .

如果我将该方法修改为仅采用一个参数( doAsregistration ),那么它就可以正常工作。

这里出了什么问题?我尝试过使用 param@RequestMapping但这也行不通。

最佳答案

您没有保护&符号免受外壳的影响,这就是为什么您还会得到其他奇怪的外壳输出。将 URL 放在引号中。

关于java - 使用 Spring MVC 处理多个 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34772502/

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