一、出现这个问题是因为存的时候redis自己有个序列化的东西
这个东西加上了以后再redis显示的就是有这些 看不懂的字符串
解决方法:
1.在redis的模块加上依赖;
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
2.写一个配置类,RedisConfig
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
FastJsonRedisSerializer<Object> fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
redisTemplate.setValueSerializer(fastJsonRedisSerializer);
redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
然后看一下你的controller层,
3.我用的是在linux里面跑的redis,看图
(1)是改过配置后显示的结果
(2)是没改过加的东西
虽然不影响结果,但是为了好看点,加两个配置文件就能更改还是很简单的;
加油 奥利给!!