SSM 運行時發生異常: Optional int parameter 'id' is present

異常:
java.lang.IllegalStateException: 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.

 

原因: 前臺傳的參數與處理參數不一致!

    @RequestMapping("/del")
    public String del(int id) {
        //調用數據
        int count= userinfoService.del(id);
        return "redirect:/list";  //直接跳轉到所有頁面
    }

 

解決:處理參數名稱不一致的情況,如果前臺傳入userId到後臺,可給該參數設置別名爲id

        例如@RequestParam(value="userId") int id)

    @RequestMapping("/del")
    public String del(@RequestParam("userId") int id) {
        //調用數據
        int count= userinfoService.del(id);
        return "redirect:/list";  //直接跳轉到所有頁面
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章