我正在尝试像这样创建简单的 REST 请求处理程序:
@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();
}
但是当我通过 CURL 测试它时:
curl http://localhost:8080/test?test=abc&number=2016
输出变成这样:
abc null
这是怎么回事?这是我的错误还是 Spring 错误? 我正在使用 Spring Boot 1.4.0(可能是最新版本)。 curl 版本为 7.43.0(64 位)。
最佳答案
希望这是解决方案而不是错误的假设:
如果你真的输入:
curl http://localhost:8080/test?test=abc&number=2016
你的 curl 过程
curl http://localhost:8080/test?test=abc
由于 &
将在后台执行和发送。
尝试:
curl 'http://localhost:8080/test?test=abc&number=2016'
。
关于java - @请求参数 : Can not get the 2nd inputted request parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39094324/