使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
2014-10-15 09:43
597 查看
错误描述:
[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)
- 问题解决: Attribute value request.getParameter("id") is quoted with " which must be escaped when used within the value
- 问题解决: Attribute value request.getParameter("id") is quoted with " which must be escaped when used wi
- 在判断Request .QueryString [\"name\"]是否为空时应注意的问题
- SpringMvc返回Json格式的数据 和@RequestMapping(value="/{username}",method=RequestMethod.GET,params="json")
- flex <param name="wmode" value="transparent">鼠标滚轮控制问题
- flex <param name="wmode" value="transparent">鼠标滚轮控制问题
- eclipse配置外部tomcat需要注意的问题。(怎样让request.getSession().getServletContext().getRealPath("/")得到正确的路径结果)
- JS中使用短路运算符(&& || & |)时需要注意的小问题
- <%@ page=""......%>标签需要注意的问题
- 在DLL编程中调用模版类时出现的类似"class“XXX”需要有 dll 接口由 class“XXX”的客户端使用"的warning的解决方案