所需的字符串参数“姓氏”不存在

时间:2019-10-02 06:18:04

标签: java spring-boot curl

这是我控制器的一部分:

@RequestMapping(value = "/addPerson", method = RequestMethod.POST)
    public void addPerson(@RequestParam("name") String name, @RequestParam("surname") String surname){
        //...
    }

这是我的cURL:

curl -X POST http://localhost:8080/addPerson?name=John&surname=Doe

请求失败:

{"timestamp":"2019-10-02T06:10:48.172+0000","status":400,"error":"Bad Request","message":"Required String parameter 'surname' is not present","path":"/addPerson"}

1 个答案:

答案 0 :(得分:0)

我通过将URL放在引号中解决了这个问题:

curl -X POST "http://localhost:8080/addPerson?name=John&surname=Doe"