问题描述
代码片段
@override public void saveliked2redis(Integer likeuserid, integer likepostid, integer likeanswerid) { String key = rediskeyutils.getlikedkey(likeuserid, likepostid, likeanswerid); redistemplate.opsforhash().put(rediskeyutils.map_key_user_liked, key, constant.redis_like_code); }
错误信息
Java.lang.classcastexception: java.lang.integer cannot be cast to java.lang.string
解决方案
在存入redis时,将传入的integer类型参数转换成string类型,修正后的代码如下:
@Override public void saveLiked2Redis(Integer likeUserID, Integer likePostID, Integer likeAnswerID) { String key = RedisKeyUtils.getLikedKey(likeUserID.toString(), likePostID.toString(), likeAnswerID.toString()); redisTemplate.opsForHash().put(RedisKeyUtils.MAP_KEY_USER_LIKED, key, Constant.REDIS_LIKE_CODE); }