SpringMVC @RequestParam

错误描述: java

[java] view plaincopy app

  1. @RequestMapping(value = "/index")   ide

  2.     public String index(@RequestParam(value = "action", required = false)   ui

  3.     String action, @RequestParam(value = "notIncludeTypeId", required = false)   spa

  4.     int notIncludeTypeId){   .net

  5.     // .... 省略代码   blog

  6. }   get

      当可选参数“notIncludeTypeId”为空时,系统出现以下错误:  it

[plain] view plaincopy io

  1. Optional int parameter 'notIncludeTypeId' is not present   

  2. but cannot be translated into a null value due to being declared as a primitive type.   

  3. Consider declaring it as object wrapper for the corresponding primitive type.  

错误缘由:

    当可选参数“notIncludeTypeId”不存在时,Spring默认将其赋值为null,但因为notIncludeTypeId已定于为基本类型int,因此赋值失败!

解决方法:

    “Consider declaring it as object wrapper for the corresponding primitive type.”建议使用包装类型代替基本类型,如使用“Integer”代替“int”

相关文章
相关标签/搜索