From acf352921487e857810a943b008121e33404e9ae Mon Sep 17 00:00:00 2001
From: kongdeqiang <kongdeqiang960204@163.com>
Date: 星期二, 15 四月 2025 16:56:50 +0800
Subject: [PATCH] fix:白名单新增bug
---
src/main/java/com/boying/util/RedisJsonUtil.java | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/boying/util/RedisJsonUtil.java b/src/main/java/com/boying/util/RedisJsonUtil.java
index 9307bf4..cb28c45 100644
--- a/src/main/java/com/boying/util/RedisJsonUtil.java
+++ b/src/main/java/com/boying/util/RedisJsonUtil.java
@@ -1,7 +1,9 @@
package com.boying.util;
+import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.jdbc.Null;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
@@ -17,21 +19,20 @@
*/
@Component
public class RedisJsonUtil {
- @Resource
- private StringRedisTemplate stringRedisTemplate;
- private final ObjectMapper objectMapper = new ObjectMapper();
+ private static StringRedisTemplate stringRedisTemplate;
- public <T> void set(String key, T value) throws IOException {
- String jsonValue = objectMapper.writeValueAsString(value);
+ public static <T> void set(String key, T value) throws IOException {
+ String jsonValue = JSON.toJSONString(value);
stringRedisTemplate.opsForValue().set(key, jsonValue);
}
- public <T> T get(String key, Class<T> type) throws IOException {
+ public static <T> T get(String key, Class<T> type) throws IOException {
String jsonValue = stringRedisTemplate.opsForValue().get(key);
- return jsonValue == null ? null : objectMapper.readValue(jsonValue, type);
+ return jsonValue == null ? null : JSON.parseObject(jsonValue, type);
}
- public void del(String key) {
+ public static void del(String key) {
stringRedisTemplate.delete(key);
}
+
}
--
Gitblit v1.9.1