原来的代码

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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐