结果是这样的:
代码是这样的:
/**
* 初始化到缓存
*/
@Component
public class InitBsDic {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Autowired
private BsDicMapper bsDicMapper;
@PostConstruct
public void contextInitializedDic() {
// 使用序列化器Jackson2JsonRedisSerializer让redisTemplate支持序列化
stringRedisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(HashMap.class));
BoundHashOperations<String, Object, Object> test = stringRedisTemplate.boundHashOps("dic_key");
Map<String, Map<Object, Object>> map = new HashMap<>();
// 查数据库
List<BsDic> listAll = bsDicMapper.selectByExample(new BsDicExample());
List<String> typeList = bsDicMapper.selectByDic