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

2021-02-25  本文已影响0人  帮我的鸵鸟盖个章

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

报错信息如下: 405

405.png

相关类如下:

@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);
    }
}

完美解决

上一篇下一篇

猜你喜欢

热点阅读