为什么在DELETE请求中需要@Responsebody而不是POST,PUT或GET?

时间:2016-05-02 21:39:01

标签: rest http spring-mvc

我在Controller类中有3种不同的方法来参与POST,PUT和DELETE HTTP方法的请求:

@RequestMapping(value = "/path1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ReturnDataType insertRequestDataType(@RequestBody RequestDataType requestData) throws ServiceException {
    //Some code here to call service class and do something with requestData
    return new ReturnDataType();
}


@RequestMapping(value = "/path2", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public ReturnDataType updateRequestDataType(@RequestBody RequestDataType requestData) throws ServiceException {
    //Some code here to call service class and do something with requestData
    return new ReturnDataType();
}

@RequestMapping(value = "path3/{arg1}/path4/{arg2}", method = RequestMethod.DELETE)
    public @ResponseBody ReturnDataType deleteRequestDataType(@PathVariable String arg1, 
                       @PathVariable String arg2) throws ServiceException {
            //Some code here to call service class and do something with arg1 and arg2
            return new ReturnDataType();
}

前两种方法在返回类型中没有@ResponseBody注释的情况下工作得很好,但最后一种方法却没有。如果我从第三种方法中删除注释,我将收到以下错误:

{
  "success": false,
  "cause": "Request method 'DELETE' not supported",
  "message": "Request Error"
}

为什么会这样?

提前感谢您的时间。

0 个答案:

没有答案