//拿到数据,redis如果有则将现在有的传进去,如果没有则获取接口
ExWritPropertyVo ExWritPropertyVo = new ExWritPropertyVo();
ExWritPropertyVo.setCaichanmingcheng("我是打电话的");
ExWritPropertyVo.setCaichanmingchengType(21);
byte[] serialize = SerializationUtils.serialize(ExWritPropertyVo);//lang3包下的
redisTemplate.opsForValue().set("u",serialize);
byte[] bs2 = (byte[]) redisTemplate.opsForValue().get("u");//redisTemplate
ExWritPropertyVo deserialize = SerializationUtils.deserialize(bs2);
System.out.println(deserialize);
小案例:
@GetMapping("/test01") public R test01(){ byte[] bs2 = (byte[])redisTemplate.opsForValue().get("zhangsan"); HashMap<String, String> ccxmapAll = new HashMap<String, String>(16); if(bs2!=null){ ccxmapAll = SerializationUtils.deserialize(bs2); } if(ccxmapAll.size()<1){ ccxmapAll.put("zhansgan","dasdsad"); byte[] serialize = SerializationUtils.serialize(ccxmapAll);//lang3包下的 redisTemplate.opsForValue().set("zhangsan",serialize); } return R.ok(ccxmapAll); }