若是将Map作为Key,存入Redis,该如何操作?

1.先封装HashMap

Map<String,Object> map=new HashMap<String,Object>();
map.put("name","老王");
map.put("id","195");

2.将map转换为JSONObject类型

JSONObject jsonObject=JSONObject.fromObject(map);

3.将jsonObject转换为字符串并打印

String str =jsonObject.toString();
System.out.println(str);

 4.将转换后的字符串str作为key存入Redis

@Cacheable(value{"userServ"},key="'userJpushObject'.concat(#str)")
@Override
public UserJpush selectByPrimaryKey(String str) {
    return getMapper().select(str);
}            

 

posted @ 2018-11-15 09:44  An-Optimistic-Person  阅读(2152)  评论(0编辑  收藏  举报