【BUG解决方案】SpringBoot接收不到POST请求的解决方案
【BUG解决方案】SpringBoot接收不到POST请求的解决方案
·
原来的代码
@PostMapping("/wx/hdrlist/{hdrWxOpenid}/{hdrStatus}")
@ResponseBody
public AjaxResult selectByOpenidAndStatus(@PathVariable("hdrWxOpenid") String openid, @PathVariable("hdrStatus") String status) {
List<ScHdr> hdrs = scHdrService.selectByOpenidAndStatus(openid, status);
return AjaxResult.success(hdrs);
}
错误原因与解决方案
前端向后端发送POST请求且携带参数为JSON类型时,后端不能简单地使用@RequestParam
接收数据
应该使用@RequestBody
、制作一个Map来接收参数
修改后的代码
@PostMapping("/wx/hdrlist")
@ResponseBody
public AjaxResult selectByOpenidAndStatus(@RequestBody Map<String, String> params) {
List<ScHdr> hdrs = scHdrService.selectByOpenidAndStatus(params.get("openid"), params.get("status"));
return AjaxResult.success(hdrs);
}
更多推荐
已为社区贡献3条内容
所有评论(0)