Optional int parameter 'xx' is present but cannot be translated into a null value

深碍√TFBOYSˉ_ 2022-05-14 11:56 255阅读 0赞

今天在controller中获取post参数时,报了如下错误

  1. {
  2. "timestamp": "2018-09-07T07:25:51.524+0000",
  3. "status": 500, "error": "Internal Server Error",
  4. "message": "Optional int parameter 'id' 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.",
  5. "path": "/user/add"
  6. }

查看报错信息

  1. Optional int parameter 'id' is present but cannot be translated into a null value

意思是id不能转换为空,后面也给出了修改的建议

  1. Consider declaring it as object wrapper for the corresponding primitive type.

可以用包装类Integer来避免这个错误

在springmvc接受参数的时候,尽量不要使用基本数据类型

发表评论

表情:
评论列表 (有 0 条评论,255人围观)

还没有评论,来说两句吧...

相关阅读