Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……

我不是女神ヾ 2024-04-22 19:12 159阅读 0赞

在这里插入图片描述

?wei_shuo的个人主页

?wei_shuo的学习社区

?Hello World !


Optional int parameter ‘id’ is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.

可选的 int 参数 ‘id’ 存在,但由于被声明为基元类型,因此无法转换为 null 值。请考虑将其声明为相应基元类型的对象包装器

错误原因:

遇到这个错误就是把参数int 改成Integer ,springmvc接受参数的时候,尽量不要使用基本数据类型

  • 原代码

    @RequestMapping(“/toUpdate”)
    public String toUpdatePaper(int id, Model model){

    1. Books books = bookService.queryBookById(id);
    2. model.addAttribute("books",books);
    3. return "updateBook";

    }

  • 修改代码

    @RequestMapping(“/toUpdate”)
    public String toUpdatePaper(Interger id, Model model){

    1. Books books = bookService.queryBookById(id);
    2. model.addAttribute("books",books);
    3. return "updateBook";

    }


? 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞?收藏⭐️评论?冲冲冲?


在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,159人围观)

还没有评论,来说两句吧...

相关阅读