首页 > 其他分享 >springboot报错:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

springboot报错:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

时间:2023-02-18 15:55:35浏览次数:49  
标签:www ResultMsg return supported 缓存 报错 ResultCode delete

控制层中,根据id删除用户是这样写的:

@PostMapping("/delete")
public ResultMsg delete(@RequestBody Map<String,Object> params){ 
	...... 
}

请求报错:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

 

解决方案1:

    @PostMapping("/delete")
    public ResultMsg delete(@RequestBody User user){
        int n = userService.delete(user.getId());
        if (n>0){
            System.out.println("删除数据成功,清除缓存");
            // 清除缓存
            redisTemplate.delete("users");
            return ResultMsg.success(ResultCode.SUCCESS);
        } else {
            return ResultMsg.fail(ResultCode.FAIL);
        }
    }

  

解决方案2:

    @PostMapping("/delete")
    public ResultMsg delete(@RequestParam Map<String,Object> params){
        Object o = params.get("id");
        if (o instanceof String){
            String string = (String)o;
            Integer integer = Integer.valueOf(string);
            int n = userService.delete(integer);
            if (n>0){
                System.out.println("删除数据成功,清除缓存");
                // 清除缓存
                redisTemplate.delete("users");
                return ResultMsg.success(ResultCode.SUCCESS);
            }
        }
        return ResultMsg.fail(ResultCode.FAIL);
    }

 

标签:www,ResultMsg,return,supported,缓存,报错,ResultCode,delete
From: https://www.cnblogs.com/uncleyong/p/17132214.html

相关文章