解决 redisTemplate的乱码问题解决办法
@Autowired
private RedisTemplate redisTemplate;
/**
* 解决redisTemplate1的乱码问题
* @param redisTemplate1
/
public void setRedisTemplate(RedisTemplate redisTemplate1) {
// 序列化为String
RedisSerializer stringSerializer = new StringRedisSerializer();
// 序列化为Json
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
System.out.println(“redisTemplate:”+redisTemplate1);
redisTemplate1.setKeySerializer(stringSerializer);
redisTemplate1.setValueSerializer(jackson2JsonRedisSerializer);
redisTemplate1.setHashKeySerializer(stringSerializer);
redisTemplate1.setHashValueSerializer(jackson2JsonRedisSerializer);
this.redisTemplate = redisTemplate1;
}
/*
*测试用例
* @param secretPlus
*/
public void insertRedis(SecretPlus secretPlus) {
setRedisTemplate(redisTemplate);
redisTemplate.delete(“1”);
redisTemplate.opsForValue().set(“1”);
}