[英]Processing multiple URL parameters with Spring MVC
I have a Spring Controller class set up with @RequestMapping("/vehicle")
set at the class level. 我有一个在类级别设置
@RequestMapping("/vehicle")
的Spring Controller类。 One method of this class is 此类的一种方法是
@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);
}
and I'm sending queries to it like: 我正在向它发送查询,例如:
curl -iv localhost:8096/vehicle/?doAs=user®istration=ABC1234
When executed, I get a response containing: 执行后,我得到一个包含以下内容的响应:
"exception":"org.springframework.web.bind.MissingServletRequestParameterException","message":"Required String parameter 'registration' is not present"
If I reverse the order of doAs
and registration
in the URL then the error says that 'doAs' is not present
. 如果我颠倒了
doAs
的顺序和URL中的registration
,则该错误表明'doAs' is not present
。
If I modify the method to only take one argument (either doAs
or registration
) then it works fine. 如果我将方法修改为仅接受一个参数(
doAs
或registration
),则它可以正常工作。
What's going wrong here? 这是怎么了 I've tried using
param
in the @RequestMapping
but that doesn't work either. 我已经尝试在
@RequestMapping
使用param
,但这也不起作用。
You're not protecting the ampersand from the shell, which is why you're also getting other weird shell output. 您没有从外壳保护&符,这就是为什么还要获得其他奇怪的外壳输出的原因。 Put the URL in quotes.
将该网址放在引号中。
Try quoting the url you are passing to curl, in other post I saw that the ampersant was backgrounding the job. 尝试引用您传递的要卷曲的URL,在另一篇文章中,我看到了“&”符正在为工作做背景。 try:
尝试:
curl -iv "localhost:8096/vehicle/?doAs=user®istration=ABC1234" curl -iv“本地主机:8096 / vehicle /?doAs = user&registration = ABC1234”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.