|
|
|
@@ -9,6 +9,7 @@ import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
|
|
|
public class RedisCacheUtils { |
|
|
|
@@ -97,10 +98,49 @@ public class RedisCacheUtils { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> T getFieldObject(Object o,String property,Class<T> clazz) { |
|
|
|
String json = JSON.toJSONString(o); |
|
|
|
JSONObject jsonObject = JSON.parseObject(json); |
|
|
|
Object p = jsonObject.get(property); |
|
|
|
if (null != p ) { |
|
|
|
return parseJson(JSON.toJSONString(p), clazz); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> List<T> getListFieldObject(Object o,String property,Class<T> clazz) { |
|
|
|
String json = JSON.toJSONString(o); |
|
|
|
JSONObject jsonObject = JSON.parseObject(json); |
|
|
|
Object p = jsonObject.get(property); |
|
|
|
if (null != p ) { |
|
|
|
return parseListJson(JSON.toJSONString(p), clazz); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> Set<T> getSetFieldObject(Object o,String property,Class<T> clazz) { |
|
|
|
String json = JSON.toJSONString(o); |
|
|
|
JSONObject jsonObject = JSON.parseObject(json); |
|
|
|
Object p = jsonObject.get(property); |
|
|
|
if (null != p ) { |
|
|
|
return parseSetJson(JSON.toJSONString(p), clazz); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static Map getMapFieldObject(Object o,String property) { |
|
|
|
String json = JSON.toJSONString(o); |
|
|
|
JSONObject jsonObject = JSON.parseObject(json); |
|
|
|
Object p = jsonObject.get(property); |
|
|
|
if (null != p ) { |
|
|
|
return parseJson(JSON.toJSONString(p), Map.class); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static void removeCache(RedisTemplate<String, Object> template,String key) { |
|
|
|
if (template.hasKey(key)) { |
|
|
|
template.delete(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |