From 1d42efe4cbd6b1028a28ff7f3ef2b3d721051c2f Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期四, 26 九月 2024 13:58:24 +0800 Subject: [PATCH] fix : 新增修改车数日志 --- 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