Optional int parameter ‘id‘ is present but cannot be translated into a null value
接收参数时遇到的问题
开始的代码
@RequestMapping("/deleteComment")@ResponseBodypublic ResultInfo deleteComment(@RequestParam(value = "comment_id",required = false) int comment_id,@RequestParam(value = "id",required = false) int id) {return commentService.deleteComment(comment_id,id);}
错误如下
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.
这段文字的意思如下
可选的int参数“id”是存在的,但是由于声明为原始类型,所以不能被转换成空值。考虑将其声明为对应原语类型的对象包装器
就是你定义的某个方法的参数,但是这个参数是非必须的,系统会自动给这个字段赋值为null,但是你的字段类型为int,int不能接收null值,所以会报如上的错误。解决办法就是使用包装类 Integer。
修改后的代码
@RequestMapping("/deleteComment")@ResponseBodypublic ResultInfo deleteComment(@RequestParam(value = "comment_id",required = false,defaultValue = "0") Integer comment_id,@RequestParam(value = "id",required = false,defaultValue = "0") Integer id) {return commentService.deleteComment(comment_id,id);}
将int 改为Integer,并给了默认值为0,业务层好使用。
Optional int parameter ‘id‘ is present but cannot be translated into a null value相关推荐
- Optional int parameter 'id' is present but cannot be translated into a null value due to being
执行## ........(int id);报出以下错误. Optional int parameter 'id' is present but cannot be translated into a ...
- Optional int parameter ‘id‘ is present but cannot be translated into a null
问题: 报错Optional int parameter 'id' is present but cannot be translated into a null @RestController pu ...
- Optional int parameter ‘xxx‘ is present but cannot be translated into a null value due to being
Optional int parameter 'domainId' is present but cannot be translated into a null value due to being ...
- Optional int parameter ‘xxx‘ is present but cannot be translated into a null value due to being decl
错误描述: processing failed; nested exception is java.lang.IllegalStateException: Optional int parameter ...
- Optional int parameter 'page' is present but cannot be translated into a null value due to being dec
这个错误犯两回了 int改integer 原始类型不能为null 包装类可以 我的spring mvc 代码: @Controller @RequestMapping("/product&q ...
- Optional int parameter ‘page‘ is present but cannot be translated into a null value due to being dec
背景:在测试上面这个controller时(status为查询条件Limit,查询status为1/0的所有记录),当用postman发出请求http://localhost:8080/orders/ ...
- Optional int parameter ‘xxx‘ is present but cannot be translated into a null value due to being.....
异常代码 `j`ava.lang.IllegalStateException: Optional int parameter 'tyId' is present but cannot be trans ...
- Optional int parameter ‘grade‘ is present but cannot be translated into a null value due to being de
完整的错误提示信息: 复制出来看的清楚些: Optional int parameter 'grade' is present but cannot be translated into a null ...
- Optional int parameter ‘categoryId‘ is present but cannot be translated into a null value due to be
Optional int parameter 'categoryId' is present but cannot be translated into a null value due to bei ...
最新文章
- 广告点击率预测_精品案例|在线广告点击率预测
- springmvc + springboot + mybatis java b2b2c电子商城系统源码...
- 脑电分析系列[MNE-Python-19]| 可视化Evoked数据
- java script 教程_Java Script入门
- 用Python学分析 - 单因素方差分析
- php_sapi常量,PHP常量PHP_SAPI与函数php_sapi_name()简介,PHP运行环境检测
- mimemultipart java_最佳实践 – 发送javamail mime multipart电子邮件和gmail
- STL学习系列一:STL(标准模板库)理论基础
- APP测试之Monkey压力测试(二)
- PCD Lesson2:PCD文件的write
- intellji External Libraries下依赖包找不到解决方法
- 线程开启方法之一——异步委托
- d3js精通教程_d3js从基础到精通第二部分
- 计算机程序试题答案,历年计算机软考程序设计模拟试题及答案
- hdoj 3533 Escape
- python父亲节祝福_用python祝福父亲节_父亲节送给父亲的祝福语,挑一句话发朋友圈!...
- 健康小贴士:喝酒时别点哪些菜_新闻中心_新浪网
- chrome清除https状态
- Java8集合的一些操作
- 概要数据结构(Sketch)
热门文章
- Python自动录入ERP系统数据
- U8如何修改单位名称和账套名称
- 为什么很多企业都在上云?云服务器到底有哪些优势?
- 策略模式(Strategy模式)
- 视频编解码绿边的问题
- 一长为 l,密度均匀的柔软链条,其单位长度的密度为 λ。将其卷成一堆放在地面上。若手握链条的一端,以匀 速 v 将其上提。当绳端提离地面的高度为 x 时,证明手 的提力为 = + 。...
- 数字识别--图像预处理之准备(归一化)
- SQL Server事务隔离级别详解
- Keil调试程序如何查看变量
- flutter不支持热更新_在iOS原生项目中使用Flutter,热更新