Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
743fce78
Commit
743fce78
authored
Aug 04, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化防重提交唯一标识
parent
8b5d2542
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
...on/src/main/java/com/ruoyi/common/constant/Constants.java
+5
-0
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
...yi/framework/interceptor/impl/SameUrlDataInterceptor.java
+10
-3
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
View file @
743fce78
...
...
@@ -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:"
;
/**
* 验证码有效期(分钟)
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
View file @
743fce78
...
...
@@ -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
<
String
,
Object
>
sessionMap
=
(
Map
<
String
,
Object
>)
sessionObj
;
...
...
@@ -77,7 +84,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
}
Map
<
String
,
Object
>
cacheMap
=
new
HashMap
<
String
,
Object
>();
cacheMap
.
put
(
url
,
nowDataMap
);
redisCache
.
setCacheObject
(
CACHE_REPEAT_KEY
,
cacheMap
,
intervalTime
,
TimeUnit
.
SECONDS
);
redisCache
.
setCacheObject
(
cache_repeat_key
,
cacheMap
,
intervalTime
,
TimeUnit
.
SECONDS
);
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment