报错java.lang.NumberFormatException: For input string: "update"

021-04-26 17:25:38.753 [http-nio-9091-exec-1] WARN [198] - Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "update"]

请求的参数是

{
    "id": 67,
    "title": "我的世界里",
    "userID": 1
}

接口处代码

@ApiOperation("用户编辑任务")
    @RequestMapping(value = "/v1/code-task/user/update", method = {RequestMethod.POST})
    public ResponseResult editCodeTaskDetailByUserID(
            HttpServletRequest request,
            @RequestBody CodeTask codeTask
    ) {
        String code = "500";
        String message = "FAIL";
        String detail = "";

        int updateRecord;
        ResponseResult responseResult = new ResponseResult();
        HttpSession session = request.getSession();

        if(session.getAttribute("userInfo") != null) {
            String userInfoStr = session.getAttribute("userInfo").toString();
            UserInfo userInfo = JSON.parseObject(userInfoStr, UserInfo.class);

            System.out.println("getId == " + codeTask.getId());
//            updateRecord = codeTaskService.updateUserCodeTaskByID(codeTask);
//            code = "200";
//            message = "SUCCESS";
//            detail = "update taskVersion";
//            responseResult.setData(updateRecord);
        } else {
            detail = "no user";
        }

        responseResult.setCode(code);
        responseResult.setMessage(message);
        responseResult.setDetail(detail);
        return responseResult;
    }
阅读 8.7k
3 个回答

是不是请求参数类型转换异常,字符串update不能转换为数字类型

看看codeTask对象和前端传递到后端的参数

感觉像是url里的update被识别为参数了。你找找有没有这样的接口/v1/code-task/user/{xxx}.
你前端的请求可能用成了GET,映射到GET /v1/code-task/user/{userId}接口上了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题