From 743fce78290f0b359d3d99b79a6c9c0a2a5a0dee Mon Sep 17 00:00:00 2001 From: RuoYi Date: Tue, 4 Aug 2020 11:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=98=B2=E9=87=8D=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=94=AF=E4=B8=80=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/constant/Constants.java | 5 +++++ .../interceptor/impl/SameUrlDataInterceptor.java | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 9ee2707..188f0b7 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -61,6 +61,11 @@ public class Constants * 登录用户 redis key */ public static final String LOGIN_TOKEN_KEY = "login_tokens:"; + + /** + * 防重提交 redis key + */ + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; /** * 验证码有效期(分钟) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java index 5f78380..36e6c10 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -5,8 +5,10 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.filter.RepeatedlyRequestWrapper; import com.ruoyi.common.utils.StringUtils; @@ -26,7 +28,9 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor public final String REPEAT_TIME = "repeatTime"; - public final String CACHE_REPEAT_KEY = "repeatData"; + // 令牌自定义标识 + @Value("${token.header}") + private String header; @Autowired private RedisCache redisCache; @@ -62,7 +66,10 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor // 请求地址(作为存放cache的key值) String url = request.getRequestURI(); - Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); + // 唯一标识(指定key + 消息头) + String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + request.getHeader(header); + + Object sessionObj = redisCache.getCacheObject(cache_repeat_key); if (sessionObj != null) { Map sessionMap = (Map) sessionObj; @@ -77,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor } Map cacheMap = new HashMap(); cacheMap.put(url, nowDataMap); - redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS); + redisCache.setCacheObject(cache_repeat_key, cacheMap, intervalTime, TimeUnit.SECONDS); return false; }