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