錯誤描述: java
[java] view plaincopy app
@RequestMapping(value = "/index") ide
public String index(@RequestParam(value = "action", required = false) ui
String action, @RequestParam(value = "notIncludeTypeId", required = false) spa
int notIncludeTypeId){ .net
// .... 省略代碼 blog
} get
當可選參數「notIncludeTypeId」爲空時,系統出現以下錯誤: it
[plain] view plaincopy io
Optional int parameter 'notIncludeTypeId' is not 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.
錯誤緣由:
當可選參數「notIncludeTypeId」不存在時,Spring默認將其賦值爲null,但因爲notIncludeTypeId已定於爲基本類型int,因此賦值失敗!
解決方法:
「Consider declaring it as object wrapper for the corresponding primitive type.」建議使用包裝類型代替基本類型,如使用「Integer」代替「int」