使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
2017-07-23 14:49
751 查看
错误描述:
[java]
view plain
copy
print?
@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?
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
[java]
view plain
copy
print?
@RequestMapping(value = "/index")
public String index(@RequestParam(value = "action", required = false)
String action, @RequestParam(value = "notIncludeTypeId", required = false)
int notIncludeTypeId){
// .... 省略代码
}
@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?
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.
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)时需要注意的问题
- 使用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)
- @RequestParam(value="id",required = false, defaultValue = 0
- php中使用$_REQUEST需要注意的一个问题
- @RequestParam(value="condition",required=false)
- @RequestParam(value = "disable", required = false)
- SpringMVC的注解使用注意问题
- 在使用 <s:iterator value="#request.students"></s:iterator> 无法显示数据,而 ${request.students[0].id} 却可以显示时问题
- eclipse配置外部tomcat需要注意的问题。(怎样让request.getSession().getServletContext().getRealPath("/")得到正确的路径结果)
- SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析
- 在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取。这里主要讲这个注解
- Attribute value request.getParameter("param") 问题