Optional int parameter 'pId' is present but cannot be translated into a null value due to being declared as a primitive type.
接口测试的时候遇到了一个问题,导致测试阻断了好久,在此记录,谨防忘记。
具体报错如下:
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.

接口测试代码如下:

出问题的就是这个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.的更多相关文章
- 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值. 难 ...
- 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 ...
- 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 ...
- 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 ...
- Optional int parameter 'id' is present but cannot be translated into a null value due to being decla
这个错误可以将参数由int改为Integer
- 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 ...
- Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present
今日, 本人在tomcat+spring mvc平台的服务器上遇到java.lang.IllegalStateException: Optional int parameter 'id' is not ...
- Required String parameter ' ' is not present
Required String parameter ' ' is not present 报错原因: url中的参数错误. 解决方法: 1.修正url中的参数的值. 2.在Controller层中的@ ...
- 使用springmvc报错Required int parameter 'age' is not present
仔细检查jsp代码 <a href="springmvc/testRequestParam?username=atguigu$age=11">Test RequestP ...
随机推荐
- 静态链表 C++版
笔记静态链表的实现 #include "stdafx.h" #include<iostream> using namespace std; #define MAXSIZ ...
- HDU 5125 magic balls(线段树+DP)
magic balls Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 排列组合( Lindström–Gessel–Viennot lemma 定理)
链接:https://www.nowcoder.com/acm/contest/139/A来源:牛客网 Monotonic Matrix 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ ...
- 44.和为S的两个数字
题目描述: 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 思路分析: 数组是递增排序的,我们先将数组遍历一遍 ...
- Resultset获取行数和列数
在Java中,获得ResultSet的总行数的方法有以下几种. 第一种:利用ResultSet的getRow方法来获得ResultSet的总行数 Statement stmt = con.create ...
- CentOS使用手册(二)
前言: 本篇目录: 1.Linux软件安装调试 2.Linux内存.CPU.进程.端口.硬盘管理 3.Linux systemctl管理服务.防火墙firewalld以及SELinux配置 Linux ...
- elasticsearch 关联单词查询以及Shingles
Shingle Token Filter A token filter of type shingle that constructs shingles (token n-grams) from a ...
- 解决mac pro 软件损坏
1,打开终端 2,输入 sudo spctl --master-disable 3,打开系统偏好设置——>安全与隐私——>勾选任何来源
- 12.Unsafe原子性操作
import sun.misc.Unsafe; /** * JDK8 * JDK 的此jar 包中的 Unsafe 类提供了硬件级别的原子性操作 */ public class UnsafeTest ...
- 【leetcode】1005. Maximize Sum Of Array After K Negations
题目如下: Given an array A of integers, we must modify the array in the following way: we choose an i an ...