0
点赞
收藏
分享

微信扫一扫

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


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

💗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){
    Books books = bookService.queryBookById(id);
    model.addAttribute("books",books);
    return "updateBook";
}
• 修改代码
@RequestMapping("/toUpdate")
public String toUpdatePaper(Interger id, Model model){
    Books books = bookService.queryBookById(id);
    model.addAttribute("books",books);
    return "updateBook";
}

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

Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……_原代码_02


举报

相关推荐

0 条评论