1.对比定制不定制的区别
不定制出现乱码且没有值
定制序列化结果,乱码解决,且结果正确显示
定制序列化后代码
1.配置类
package com.by.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
//利用springboot约定大于配置的特点,命名为这个name = "redisTemplate",就不用springboot里面的了
@Bean(name = "redisTemplate")
public RedisTemplate
测试类
@SpringBootTest
class RedisTemplateDemoTest {
@Resource(name = "redisTemplate")
private RedisTemplate redisTemplate1;
@Test
void test() {
redisTemplate1.opsForValue().set(key,"周星星");
Object o = redisTemplate1.opsForValue().get(key);
System.out.println(o);
}
}



