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

发布于 2022-09-12 23:26:45 字数 1664 浏览 7 评论 0

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赏烟花じ飞满天 2022-09-19 23:26:45

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

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

深陷 2022-09-19 23:26:45

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

梦回梦里 2022-09-19 23:26:45

springMVC在把json转换为CodeTask对象时异常,再检查下传入的参数吧

已参与了 SegmentFault 思否「问答」打卡,欢迎正在阅读的你也加入。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文