在 curl GET 请求中的多个请求参数上获取空指针异常



1,单个请求参数的 curl 命令:

curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1工作正常。

2、用于多个请求参数的 curl 命令:

curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1&pageNumber=0我得到页面编号为空,抛出空指针异常

示例 Java 控制器类

@Controller
@RequestMapping("/api/test")
public class TestController {
@RequestMapping(method = RequestMethod.GET, producesMediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> getTest(
@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam(value = "pageNumber", required = false) Integer pageNumbe,
HttpServletRequest hsrequest, HttpServletResponse hsresponse) {
//implementation
}

2、用于多个请求参数的 Curl 命令:

curl --insecure -X GET "Content-Type:application/json" https://localhost/test?pageSize=1&pageNumber=0

解决方案:向网址添加引号

curl --insecure -X GET "Content-Type:application/json" "https://localhost/test?pageSize=1&pageNumber=0"

最新更新