我是靠谱客的博主 追寻小熊猫,这篇文章主要介绍使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题,现在分享给大家,希望可以做个参考。

错误描述:

[java] view plain copy
print ?
  1. @RequestMapping(value = "/index")  
  2.     public String index(@RequestParam(value = "action", required = false)  
  3.     String action, @RequestParam(value = "notIncludeTypeId", required = false)  
  4.     int notIncludeTypeId){  
  5.     // .... 省略代码  
  6. }  
@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
print ?
  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.  
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”

博客原地址:http://blog.csdn.net/hellostory/article/details/7519358


最后

以上就是追寻小熊猫最近收集整理的关于使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题的全部内容,更多相关使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(112)

评论列表共有 0 条评论

立即
投稿
返回
顶部