java.lang.IllegalStateException: Optional int parameter 'pageSize' is present but cannot be translat
2017-07-12 10:22
676 查看
我的spring mvc 代码:
[java] view
plain copy
@Controller
@RequestMapping("/product")
public class Fancy {
@RequestMapping(value = "/fancy")
@ResponseBody
public String showFancy(@RequestParam(value = "page", required = false) int page) {
return "{\"status\":\"ok\"+}"+page+"\t";
}
}
报错:
[plain] view
plain copy
Optional int parameter 'page' is present but cannot be translated into a null value due to being dec
继续查看出错内容:
[plain] view
plain copy
Request processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter 'page' is 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
大意是说 如果参数是非必须的,则会赋值为null,因此参数应该是一个object,它才能接受这个null值。
而上面代码参数page 的类型 为 int,它接受不了null值。
解决方法:
将int 改为 对象类型 Integer :
[plain] view
plain copy
@RequestParam(value = "page", required = false) Integer page
问题解决。
[java] view
plain copy
@Controller
@RequestMapping("/product")
public class Fancy {
@RequestMapping(value = "/fancy")
@ResponseBody
public String showFancy(@RequestParam(value = "page", required = false) int page) {
return "{\"status\":\"ok\"+}"+page+"\t";
}
}
报错:
[plain] view
plain copy
Optional int parameter 'page' is present but cannot be translated into a null value due to being dec
继续查看出错内容:
[plain] view
plain copy
Request processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter 'page' is 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
大意是说 如果参数是非必须的,则会赋值为null,因此参数应该是一个object,它才能接受这个null值。
而上面代码参数page 的类型 为 int,它接受不了null值。
解决方法:
将int 改为 对象类型 Integer :
[plain] view
plain copy
@RequestParam(value = "page", required = false) Integer page
问题解决。
相关文章推荐
- java.lang.IllegalStateException: Optional long parameter 'adminId' is present but cannot be translat
- java.lang.IllegalStateException: Optional int parameter 'studentid' is present but cannot be transla
- Optional int parameter 'pageNumber' is present but cannot be translated into a null value due to bei
- Optional int parameter 'page' is present but cannot be translated into a null value due to being dec
- Optional int parameter 'id' is present but cannot be translated into a null value due to being decla
- Optional int parameter 'topicId' is present but cannot be translated into a null value due to being
- Optional int parameter 'projectId' is present but cannot be translated into a null value due to bein
- Optional int parameter 'folderId' is not present but cannot be translated into a null value due to b
- Optional int parameter 'version' is present but cannot be translated into a null value due to being
- Optional int parameter 'rip' is present but cannot be translated into a null value due to being decl
- Optional int parameter 'id' is present but cannot be translated into a null value due to being decla
- java.lang.IllegalStateException: File has been moved - cannot be read again
- nested exception is java.lang.ClassCastException: java.lang.IllegalArgumentException cannot be cast
- nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed
- nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframewo
- nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map ***
- java.lang.IllegalArgumentException: Resources cannot be null
- java.lang.IllegalStateException: Cannot forward after response has been committed异常
- Eclipse error: The type java.lang.Object cannot be resolved. It is indirectly referenced from the required .class files
- 1、The type java.lang.Object cannot be resolved.It is indirec....