使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
2014-07-15 14:36
627 查看
错误描述:
[java] view plaincopy
@RequestMapping(value = "/index")
public String index(@RequestParam(value = "action", required = false)
String action, @RequestParam(value = "notIncludeTypeId", required = false)
int notIncludeTypeId){
// .... 省略代码
}
当可选参数“notIncludeTypeId”为空时,系统出现如下错误:
[plain] view plaincopy
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”
[java] view plaincopy
@RequestMapping(value = "/index")
public String index(@RequestParam(value = "action", required = false)
String action, @RequestParam(value = "notIncludeTypeId", required = false)
int notIncludeTypeId){
// .... 省略代码
}
当可选参数“notIncludeTypeId”为空时,系统出现如下错误:
[plain] view plaincopy
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”
相关文章推荐
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- 使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
- SpringMVC上传文件需要注意的地方:@RequestParam(value = "file", required = false) MultipartFile file
- springmvc中关于@RequestParam(value="xxx",required=false) int xxx的一个坑
- spring 注解上传文件 @RequestParam(value = "file1", required = false)
- Spring——注解上传文件.@RequestParam(value = "file1", required = false) ;
- php中使用$_REQUEST需要注意的一个问题
- php中使用$_REQUEST需要注意的一个问题
- @RequestParam(value = "disable", required = false)
- @RequestParam(value="condition",required=false)
- SpringMVC学习 -- @RequestParam , @RequestHeader , @CookieValue 的使用
- @RequestParam(value="id",required = false, defaultValue = 0
- 在使用 <s:iterator value="#request.students"></s:iterator> 无法显示数据,而 ${request.students[0].id} 却可以显示时问题
- Spring MVC 的@RequestParam注解和request.getParameter("XXX")
- Attribute value request.getParameter("param") 问题
- springMVC的@ResponseBody、@RequestBody使用需要注意的地方