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

{ 
    "timestamp": "2018-09-07T07:25:51.524+0000", 
    "status": 500, "error": "Internal Server Error", 
    "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.", 
    "path": "/user/add" 
}

查看报错信息

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

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

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

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

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

Logo

昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链

更多推荐