我有一类不同的数据类型 . 其中一个是 Integer
的 Integer
键和int数组值(它有24个单元格) . 我使用Spring Data将类存储在Redis中,但是当我从Redis获取它时,它会出现以下错误 .
这是 Map :
Map<Integer, int[]> mymap = new Hashmap<>();
这是错误:
org.springframework.data.mapping.MappingException: Problem deserializing 'setterless' property ("mymap"): no way to handle typed deser with setterless yet
是否还有其他方法可以序列化和反序列化 mymap
?或者我应该想到存储这个变量的其他方法?
编辑:
这是我的 class :
private String word;
private int DF;
private boolean NE;
private double mean;
private Map<Integer, Burst> interal = new HashMap<>();
private Map<String, Date> docs = new HashMap<>();
private Map<Integer, int[]> TWF;
这是我的redis配置:
public class redisConfig {
@Primary
@Bean("rediscf1")
JedisConnectionFactory jedisConnectionFactory1() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
redisStandaloneConfiguration.setDatabase(0);
return new JedisConnectionFactory(redisStandaloneConfiguration, new JedisConfig());
}
@Primary
@Bean(name = "redis1")
public RedisTemplate<String, Object> redisTemplate1(@Qualifier("rediscf1") JedisConnectionFactory cf) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(cf);
return template;
}}
1 回答
我的Redis配置:
(我建议将此处的Object更改为要保存的实体类的类)
接下来我有两节课 . save和TestClass的实体就像你的"Burst"类一样 . 请记住添加所有保存类 implements Serializable .
并保存数据代码:
RedisTemplate是自动装配的 .
所有工作都可以使用你的类中的其他类型(Date,int,boolean)