接口测试的时候遇到了一个问题,导致测试阻断了好久,在此记录,谨防忘记。

具体报错如下:

Optional int parameter 'pId' 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.

接口报错.png

接口测试代码如下:

图片.png

出问题的就是这个pId,

百度了下这个问题的原因,归根结底就是参数类型错误了:

可选的参数 pId不存在,但无法被转换为NULL,是因为你把它给定义为 基本类型。建议将其修改为 包装类型。

就是说,你定义了参数:String pId,但没有值,那按理来说按照null来处理,结果倒霉的事情来了:pId= null; 是不允许的,因为基础类型不能赋值为null。

所以建议把参数定义修改为Inteter pId.


那为啥用Integer可以,用int不行呢,原因如下:

Integer 允许为null值,int默认0,数据库里面如果有个字段没有值可能默认值为null,所以用Integer。

在hashmap中只能用Integer而不能用int

int是基本数据类型,定义一个整型数据。Integer是一个类,在hashmap中代表一个对象,所以用object表示。

原文地址:https://www.jianshu.com/p/1153070468e1

Optional int parameter 'pId' is present but cannot be translated into a null value due to being declared as a primitive type.的更多相关文章

  1. Optional int parameter 'fundID' is present but cannot be translated into a null value due to being declared as a primitive type

    错误的意思是: "可选的int参数'fundID'存在但由于被声明为基本类型而无法转换为空值" 意思是fundID被申明为int的基本数据类型, 不能转换为字符串的null值. 难 ...

  2. is present but cannot be translated into a null value due to being declared as a primitive type

    解决办法:把基本类型改为对象,譬如此处将pageId的类型由int 改为Integer 2016-10-19 19:36:11.275 DEBUG [http-nio-9999-exec-2][org ...

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

  4. Optional int parameter 'rows' is not present but cannot be translated into a null value due to being declared as a primitive type.

    我的spring mvc 代码: @Controller @RequestMapping("/product") public class Fancy { @RequestMapp ...

  5. Optional int parameter 'id' is present but cannot be translated into a null value due to being decla

    这个错误可以将参数由int改为Integer

  6. Optional int parameter 'resourceState' is present but cannot be translated into a null value

    错误日志: java.lang.IllegalStateException: Optional int parameter 'resourceState' is present but cannot ...

  7. Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present

    今日, 本人在tomcat+spring mvc平台的服务器上遇到java.lang.IllegalStateException: Optional int parameter 'id' is not ...

  8. Required String parameter ' ' is not present

    Required String parameter ' ' is not present 报错原因: url中的参数错误. 解决方法: 1.修正url中的参数的值. 2.在Controller层中的@ ...

  9. 使用springmvc报错Required int parameter 'age' is not present

    仔细检查jsp代码 <a href="springmvc/testRequestParam?username=atguigu$age=11">Test RequestP ...

随机推荐

  1. HDU 6470 /// 矩阵快速幂

    题目大意: f[1]=1 f[2]=2 f[n]=f[n-1]+2*f[n-2]+n^3 在某博客截的图 现在忘记原博位置了 抱歉 根据递推式1和递推式3构造出两个矩阵 #include <bi ...

  2. Centos7 部署ftp

    1.查看是否已经安装 vsftpd -version 2.安装vsftpd yum install -y vsftpd 3.新建FTP目录 mkdir /data/KodServer/data/Use ...

  3. 练手项目之image caption问题记录

    小白一个,刚刚费了老大的劲完成一个练手项目--image caption,虽然跑通了,但是评估结果却惨不忍睹.于是贴上大神的作品,留待日后慢慢消化.顺便记录下自己踩坑的一些问题. 先膜拜下大神的作品. ...

  4. ECUST_Algorithm_2019_4

    简要题意及解析 1001 第三次作业原题,略. 1002 把一个数转换为二进制. 不断除以\(2\)取余就好了.写递归代码会非常短. 时间复杂度\(O(Tlogn)\) \(T\)是数据组数,\(n\ ...

  5. css强制换行和超出部分隐藏实现

    一.强制换行 1 word-break: break-all; 只对英文起作用,以字母作为换行依据. 2 word-wrap: break-word; 只对英文起作用,以单词作为换行依据. 3 whi ...

  6. 卸载Anaconda

    conda install anaconda-clean anaconda-clean --yes Anaconda 安装的时候在 .bash_profile中添加了变量: export PATH=& ...

  7. 在 IntelliJ IDEA 中这样使用 Git,效率提升2倍以上

    1.Git简介 Git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...

  8. 【JVM】内存区域

    程序运行时,有六个地方都可以保存数据: 1. 寄存器:这是最快的保存区域,因为它位于和其他所有保存方式不同的地方:处理器内部.然而,寄存器的数量十分有限,所以寄存器是根据需要由编译器分配.我们对此没有 ...

  9. Linq 使用Startswith 出现空引用的问题

    一.问题 我使用的是Entity Fromwork CodeFirst来操作数据库,昨天在使用startswith查询数据的时候发现一个问题,就是经常一直报空引用的错误,查了很久才找到原因,这里做一个 ...

  10. Java中的小知识。

    package jicheng; public class Animal { //定义一个成员变量name. private String name; public String getName() ...