spring mvc 中required什么意思

如题所述

第1个回答  2016-06-17
错误描述:

[java] view plain copy
@RequestMapping(value = "/index")
public String index(@RequestParam(value = "action", required = false)
String action, @RequestParam(value = "notIncludeTypeId", required = false)
int notIncludeTypeId){
// .... 省略代码
}

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

[plain] view plain copy
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”本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网