今天在操作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, 一样也是不行的。

Optional int parameter 'time' is present but cannot be translated into a null value due to being decla的更多相关文章

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

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

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

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

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

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

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

  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. iOS - url中文和特殊字符转码###

    - (NSString *)generateUrl:(NSString *)url{ /** 第一个参数:NULL 第二个参数:C语言的字符串 第三个参数:NULL 第四个参数:要转义的字符串,不要乱 ...

  2. Java语言如何进行异常处理,关键字:throws、throw、try、catch、finally分别如何使用?

    先上代码再进行分析 public class Test { public static void main(String[] args) { try{ int i = 100 / 0; System. ...

  3. 关于angularjs中的ng-class的使用

    在angularjs中,包子认为ng-class的用法是相当的大,这个相当于jquery的addClass和removeClass.在这个地方,废话不多说,直接上一小段代码 当kefu这个变量为真的时 ...

  4. php自定义函数: 下载远程文件 httpcopy

    <?php function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo( ...

  5. python基础里的那些为什么?

    一.执行python脚本的两种方式? 直接在解释器里编写并在解释器里执行 文件编写,并在终端通过 python 路径  这种方式执行 好,我们就以输出hello world这个例子来比较两种方式的不同 ...

  6. AWS入门-1

    对于 Amazon Linux AMI,用户名为 ec2-user. 对于 RHEL AMI,用户名称是 ec2-user 或 root. 对于 Ubuntu AMI,用户名称是 ubuntu 或 r ...

  7. MySQL中myisam和innodb的主键索引有什么区别?

    MyISAM引擎使用B+Tree作为索引结构,叶节点的data域存放的是数据记录的地址.下图是MyISAM索引的原理图: 这里设表一共有三列,假设我们以Col1为主键,则上图是一个MyISAM表的主索 ...

  8. Android系统移植与调试之------->如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏

    这两天由于一个客户的要求,将MID竖屏时候的状态条上的音量键去掉.所以尝试修改了一下,成功了,分享一下经验. 先看一下修改后的效果图,如下所示 . 横屏的时候:有音量加减键 竖屏的时候:音量加减键被去 ...

  9. Python排列组合

    product 笛卡尔积 (有放回抽样排列) permutations 排列 (不放回抽样排列) combinations 组合,没有重复 (不放回抽样组合) combinations_with_re ...

  10. (2)linux未使用eth0,未使用IPV4导致无法连接

    首先ifconfig查看网络IP 看,我这里默认启用了2个网卡,一个是eth0,另一个是lo(基于loopback方式) 1.如果有eth0则做:界面修改 (1)输入命令setup,选择network ...