From cf429a27ea10727884bfd57dc7fd3b3ffdb697c8 Mon Sep 17 00:00:00 2001 From: erdanergou Date: Tue, 9 May 2023 09:23:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0redistemplate=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../depository_manage/intercepter/UserInterceptor.java | 10 +++++++++- .../com/dreamchaser/depository_manage/OtherTest.java | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java b/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java index 64d12d7d..82d8f40b 100644 --- a/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java +++ b/src/main/java/com/dreamchaser/depository_manage/intercepter/UserInterceptor.java @@ -8,6 +8,7 @@ import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; import com.dreamchaser.depository_manage.security.pool.RedisPool; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -34,11 +35,14 @@ public class UserInterceptor extends HandlerInterceptorAdapter { } }; private static RedisPool redisPool; + private static RedisTemplate redisTemplate; @Autowired public void setRedisTemplate(RedisPool redisPool) { UserInterceptor.redisPool = redisPool; } + @Autowired + public void setRedisTemplate(RedisTemplate redisTemplate){UserInterceptor.redisTemplate = redisTemplate;} @Override public boolean preHandle(HttpServletRequest request, @@ -66,7 +70,11 @@ public class UserInterceptor extends HandlerInterceptorAdapter { } System.out.println("redis请求key:"+PublicConfig.LoginRedisPrefix+userKey); token = (String) redisPool.getRedisTemplateByDb(5).opsForHash().get(PublicConfig.LoginRedisPrefix+userKey,"usertoken"); - System.out.println("redis获取的token"+token); + System.out.println("redisPool获取的token: "+token); + System.out.println("redisTemplate获取的token: "+redisTemplate.opsForHash().get(PublicConfig.LoginRedisPrefix+userKey,"usertoken")); + if(token == null){ + redisPool.getRedisTemplateByDb(5).opsForHash().put("ces","wfdl","wfdl"); + } if ( "/".equals(servletPath)) { // 如果是企业微信登录 try { diff --git a/src/test/java/com/dreamchaser/depository_manage/OtherTest.java b/src/test/java/com/dreamchaser/depository_manage/OtherTest.java index 1de50b52..4808fd25 100644 --- a/src/test/java/com/dreamchaser/depository_manage/OtherTest.java +++ b/src/test/java/com/dreamchaser/depository_manage/OtherTest.java @@ -99,8 +99,9 @@ public class OtherTest { @Test public void someTest(){ - Map allDepositoryNameAndId = depositoryService.findAllDepositoryNameAndId(); - System.out.println(JSONObject.toJSONString(allDepositoryNameAndId)); + String local = "HXGK_GO_ZhixingCollege:ScanCode:Authentication:LoginApi_dev_e3bfa398fe9d0e1ab78a00ff59eff788"; + Object usertoken = redisPool.getRedisTemplateByDb(5).opsForHash().get(local, "usertoken"); + System.out.println(usertoken); } @Test