... cannot be translated into a null value due to being declared as a primitive type 解决方法

... cannot be translated into a null value due to being declared as a primitive type 解决方法,第1张

问题描述

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter ‘pageNo’ 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.

(请求处理失败;嵌套的例外是java.lang.IllegalStateException:存在可选的int参数“pageNo”,但由于被声明为基元类型,因此无法转换为null值。考虑将其声明为相应基元类型的对象包装器。)


原因分析:

int 不可以为null,但int的包装类Integer可以为null。

//错误代码:参数可能是null,用int会出错
public Object query(int pageNo,int pageSize){
}

解决方案:

将参数类型由int改为Integer即可

public Object query(Integer pageNo,Integer pageSize){
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/756358.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-30
下一篇 2022-04-30

发表评论

登录后才能评论

评论列表(0条)

保存