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); }