java.lang.Integer cannot be cast to java.lang.Long

Long incrSec = (Long) redisTemplate.opsForHash().get("redisLimitSec:" + limitKey, datekey);

解决的方法:使用String中转一下

Long incrSec = Long.parseLong(redisTemplate.opsForHash().get("redisLimitSec:" + limitKey, datekey).toString());

出现的原因:(根本的原因还是没有解决)

edisTemplate.opsForHash().get("redisLimitSec:" + limitKey, datekey).toString()返回的是object

但是 instanceof   是Integer,这样把这种类型的转成Long是不允许的

基本数据类型和引用类型不能进行强转,而Object非基本,所以必须先强转为Number,


版权声明:本文为yz18931904原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。