Java @Requestparam:无法获取第二个输入的请求参数
我正在尝试创建简单的REST请求处理程序,如下所示:Java @Requestparam:无法获取第二个输入的请求参数,java,spring,spring-mvc,curl,Java,Spring,Spring Mvc,Curl,我正在尝试创建简单的REST请求处理程序,如下所示: @RequestMapping(value = "test", method = RequestMethod.GET) public String test(@RequestParam(name = "test", required = false) String test, @RequestParam(name ="number", required = false) Long number) {
@RequestMapping(value = "test", method = RequestMethod.GET)
public String test(@RequestParam(name = "test", required = false) String test,
@RequestParam(name ="number", required = false) Long number) {
return new StringBuilder(test).append(" ").append(number).toString();
}
abc null
但当我用旋度来测试时:
curl http://localhost:8080/test?test=abc&number=2016
输出如下所示:
@RequestMapping(value = "test", method = RequestMethod.GET)
public String test(@RequestParam(name = "test", required = false) String test,
@RequestParam(name ="number", required = false) Long number) {
return new StringBuilder(test).append(" ").append(number).toString();
}
abc null
这里怎么了?这是我的错还是弹簧虫?
我使用的是Spring Boot 1.4.0最新版本。
curl版本是7.43.0 64位。希望这是解决方案,而不是错误的假设: 如果你真的打字: 卷曲http://localhost:8080/test?test=abc&number=2016 你的卷曲过程 卷曲http://localhost:8080/test?test=abc 将在后台执行并发送,因为& 尝试:
卷曲'http://localhost:8080/test?test=abc&number=2016”。希望这是解决方案,而不是错误的假设: 如果你真的打字: 卷曲http://localhost:8080/test?test=abc&number=2016 你的卷曲过程 卷曲http://localhost:8080/test?test=abc 将在后台执行并发送,因为& 尝试:
卷曲'http://localhost:8080/test?test=abc&number=2016“.在Windows 8.1上使用了cmder中的curl。多个Spring@RequestParam注释存在相同问题。用单引号将url括起来并不能解决我的问题,但双引号的效果和预期的一样 无报价方法:
curl http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate
curl 'http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate'
将产生400个错误请求错误,因为在Spring控制器中jobDate参数标记为强制参数
单引号方法:
curl http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate
curl 'http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate'
将产生的“jobDate”未被识别为内部或外部命令、可操作程序或批处理文件。错误
双引号将按预期的方式运行:
curl "http://localhost:8080/jobs/test%20name/find?jobDate=jobdate&jobTime=jobtime"
从控制器类生成正确的输出
如果通过浏览器地址栏执行相同的精确GET请求,则该请求工作正常,没有任何引号。使用了Windows 8.1上cmder的curl。多个Spring@RequestParam注释存在相同问题。用单引号将url括起来并不能解决我的问题,但双引号的效果和预期的一样 无报价方法:
curl http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate
curl 'http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate'
将产生400个错误请求错误,因为在Spring控制器中jobDate参数标记为强制参数
单引号方法:
curl http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate
curl 'http://localhost:8080/jobs/test%20name/find?jobTime=jobtime&jobDate=jobdate'
将产生的“jobDate”未被识别为内部或外部命令、可操作程序或批处理文件。错误
双引号将按预期的方式运行:
curl "http://localhost:8080/jobs/test%20name/find?jobDate=jobdate&jobTime=jobtime"
从控制器类生成正确的输出
如果通过浏览器地址栏执行相同的精确GET请求,则无需任何引用即可正常工作。谢谢,它的工作方式非常出色。P/S:虽然我在windows上检查了它,所以我用它代替了“谢谢你,它很有魅力”。P/S:虽然我在windows上检查过,所以我用