From ab99a72b65184035f48ccd0bb4f5465a0cd6b1ae Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 14 八月 2023 19:11:13 +0800 Subject: [PATCH] 优化代码 --- ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java | 25 +++++++++++++------------ 1 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java index bce2f3f..e41968a 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java @@ -5,19 +5,19 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Component; import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; -import com.alibaba.fastjson.JSONObject; +import org.springframework.web.servlet.HandlerInterceptor; +import com.alibaba.fastjson2.JSON; import com.ruoyi.common.annotation.RepeatSubmit; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.ServletUtils; /** * 防止重复提交拦截器 - * + * * @author ruoyi */ @Component -public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter +public abstract class RepeatSubmitInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception @@ -29,10 +29,10 @@ RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); if (annotation != null) { - if (this.isRepeatSubmit(request)) + if (this.isRepeatSubmit(request, annotation)) { - AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试"); - ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult)); + AjaxResult ajaxResult = AjaxResult.error(annotation.message()); + ServletUtils.renderString(response, JSON.toJSONString(ajaxResult)); return false; } } @@ -40,16 +40,17 @@ } else { - return super.preHandle(request, response, handler); + return true; } } /** * 验证是否重复提交由子类实现具体的防重复提交的规则 - * - * @param httpServletRequest - * @return + * + * @param request 请求信息 + * @param annotation 防重复注解参数 + * @return 结果 * @throws Exception */ - public abstract boolean isRepeatSubmit(HttpServletRequest request); + public abstract boolean isRepeatSubmit(HttpServletRequest request, RepeatSubmit annotation); } -- Gitblit v1.9.2