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

具体报错如下:

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. JavaFx开发桌面软件

    JavaFx开发桌面软件 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} Jav ...

  2. mySQL查看存储过程、函数、视图、触发器

    一.查看存储过程 1.show procedure status; //查看所有的 2.show create procedure proc_AllUser[proc_name]; 查看proc_Al ...

  3. IntelliJ IDEA 常用快捷键和技巧

    IntelliJ Idea 常用快捷键列表 Alt+回车 导入包,自动修正Ctrl+N  查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L  格式化代码Ctrl+Alt+O 优化导入的类和 ...

  4. Linux运维常用脚本整理

    .查找当前目录下占用为0字节的文件并删除 find ./ -type f -size -exec rm -rf {}\;    #此命令不要用于对根目录0字节文件的操作 .将系统进程按内存占用大小排列 ...

  5. line vty 0 4的意义

    VTY是路由器的远程登陆的虚拟端口,0 4表示可以同时打开5个会话,line vty 0 4是进入VTY端口,对VTY端口进行配置,比如说配置密码,或者ACL. 进入VTY 0 0 好象没什么实际操作 ...

  6. PHP+Redis 有序集合实现 24 小时排行榜实时更新

    基本介绍 Redis 有序集合和集合一样也是 string 类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个 double 类型的分数.redis 正是通过分数来为集合中的成员进行从 ...

  7. 【leetcode】994. Rotting Oranges

    题目如下: In a given grid, each cell can have one of three values: the value 0 representing an empty cel ...

  8. shell 判断字符串是否包含另一个字符串

    1.使用grep s1="abcdefg" s2="bcd" result=$(echo $s1 | grep "${s2}") if [[ ...

  9. Mac系统下安装Homebrew后无法使用brew命令

    打开终端输入 brew提示:command not found 解决方法 输入命令: sudo vim .bash_profile 然后输入以下代码: export PATH=/usr/local/b ...

  10. 【集群】Redis的哨兵模式和集群模式

    哨兵模式 哨兵模式是redis高可用的实现方式之一 使用一个或者多个哨兵(Sentinel)实例组成的系统,对redis节点进行监控,在主节点出现故障的情况下,能将从节点中的一个升级为主节点,进行故障 ...