Optional int parameter ‘time’ is present but cannot be translated into a null value due to being decla
今天在操作redis的时候报了这个错:Optional int parameter ‘time’ is present but cannot be translated into a null value due to being decla

这句话意思:参数time存在,但是无法将其转为为null

查看了下原因,time这个字段是用来记录设置多久时间过期的,

我在service层设置的是Long 类型, 我在Controller 层设置的是long类型,前后设置的不一样,猜测前后需要设置一致,

于是我就将Contoller 设置为了Long类型,于是就通过了。

但是我在接受前台传送过来的参数时,使用Long接收, 在Service层使用long 同样没有报错。

之后我更改为前后都使用long,然后就报错了。

想了下springmvc在接受参数的时候,如果不存在,那么会将这个值设置为null,如果你用基本数据类型,

那么怎么给其赋值为空呢?

总结:大家以后在springmvc接受参数的时候,尽量不要使用基本数据类型,当然你一定要使用的话,可以把defaultValue加上,这样就不会报这个错误了。
注意:就算你加上required=false, 一样也是不行的。

@RequestParam注解的使用

RequestParam来映射请求参数
required表示是否

java.lang.IllegalStateException: Optional int parameter 'studentid' is present but cannot be transla相关推荐

  1. java.lang.IllegalStateException: Optional int parameter 'ww_id' is present but cannot be translated

    这个错误我百度首先找到了一个![在这里插入图片描述](https://img-blog.csdnimg.cn/20190603195425696.png?x-oss-process=image/wat ...

  2. java.lang.IllegalStateException: Optional long parameter 'adminId' is present but cannot be translat

    把 long 换成 Long 转载于:https://my.oschina.net/LinuxDaxingxing/blog/917158

  3. 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 ...

  4. 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 ...

  5. Optional int parameter xxx is present but cannot be translat

    java.lang.IllegalStateException: Optional int parameter 'pageCode' is present but cannot be translat ...

  6. 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 ...

  7. 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 ...

  8. 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/ ...

  9. Optional int parameter ‘id‘ is present but cannot be translated into a null value

    接收参数时遇到的问题 开始的代码 @RequestMapping("/deleteComment")@ResponseBodypublic ResultInfo deleteCom ...

最新文章

  1. 再读《数量生态学:R语言应用》
  2. 【rnnoise源码分析】compute_frame_feature函数
  3. LeetCode总结 -- 树的遍历篇
  4. How your face shapes your economic chances
  5. Java自带的多线程监控分析工具(VisualVM)
  6. 报名 | 网易MCtalk: 5G+AI新时代 探索音视频技术创新与实践
  7. 你已经用上 5G 网络了吗?
  8. Azure 内容审查器之羞羞图审查
  9. 利用Mybatis对数据库进行增删改查操作
  10. CGI(通用网关接口)
  11. round()四舍五入方法的简单使用
  12. smartadmin_smartadmin官网_smartadmin下载 bootstrap 后台模板 下载-很不错的后台模板
  13. OpenCV图像处理----图像的二值化
  14. scratch节假日课程:春节舞狮
  15. 基于存储卡的音乐播放器0.6
  16. mkv转mp4,mkv转换mp4格式
  17. 王者荣耀登录显示换服务器是不是封号,王者荣耀这么查看封号原因?千万不要这么做!...
  18. linux清理dns缓存命令,Ubuntu下清空DNS缓存 提升访问速度
  19. Python自学之路第十四步——与周杰伦有关的岁月
  20. .md文件是什么?.md如何打开?怎么打开?

热门文章

  1. 软件测试-黑盒测试2
  2. JavaFx——动态时钟的实现(线程,线程池)
  3. 判断一个字符串是否是数字
  4. JAVA .class 文件防止反编译。
  5. 菜鸟小技巧:如何在网上隐藏自己的IP地址(1)
  6. A股市场上股票行情数据接口有那几种?
  7. 【Paper】2021_多智能体系统编队跟踪控制_张晓广
  8. 自律 | 最大的修养——妙算哥
  9. 六石编程学:抄代码是个技术活,大多数人不传抄
  10. python all函数用法