解决springboot中只支持get请求,无法支持post请求

x33g5p2x  于2022-05-18 转载在 Spring  
字(1.2k)|赞(0)|评价(0)|浏览(666)

解决springboot中只支持get请求,无法支持post请求

报错信息如下: 405

相关类如下:

@RestController
@RequestMapping
public class HttpServiceController {

    @Autowired
    private HttpSecretReport httpSecretReport;
    @Autowired
    private HttpSecretRecording httpSecretRecording;

    @PostMapping(value="/secret_report", produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object getCallRecordBySecretReport1(@RequestBody String requestBody){
        return httpSecretReport.dealHttpSecretReport(HttpMethodNameEnum.HTTP_SECRET_REPORT_HOME_DISPATCH.code,requestBody);
    }
}

解决办法:@RequestMapping 增加post方法支持 @RequestMapping(value = "/call_record",method = {RequestMethod.GET,RequestMethod.POST})

@RestController
@RequestMapping(value = "/call_record",method = {RequestMethod.GET,RequestMethod.POST})
public class HttpServiceController {

    @Autowired
    private HttpSecretReport httpSecretReport;
    @Autowired
    private HttpSecretRecording httpSecretRecording;

    @PostMapping(value="/secret_report", produces="application/json;charset=UTF-8")
    @ResponseBody
    public Object getCallRecordBySecretReport1(@RequestBody String requestBody){
        return httpSecretReport.dealHttpSecretReport(HttpMethodNameEnum.HTTP_SECRET_REPORT_HOME_DISPATCH.code,requestBody);
    }
}

完美解决

相关文章