<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                @author [ksf](https://blog.csdn.net/sinat_19528249) 處理的方式有兩種,本次介紹普適性方案,解決問題1。 1.正常業務請求的防止限制 2.極端情況下的請求,rediskey過期帶來的重復請求。 **代碼結構比較清晰,直接貼代碼啦:** ```java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface LimitSubmit { String key() ; /** * 默認 10s */ int limit() default 10; /** * 請求完成后 是否一直等待 * true則等待 * @return */ boolean needAllWait() default true; } ``` ```java Component @Aspect @Slf4j public class LimitSubmitAspect { //封裝了redis操作各種方法 @Autowired private RedisUtil redisUtil; @Pointcut("@annotation(org.jeecg.common.aspect.annotation.LimitSubmit)") private void pointcut() {} @Around("pointcut()") public Object handleSubmit(ProceedingJoinPoint joinPoint) throws Throwable { LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal(); Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); //獲取注解信息 LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class); int submitTimeLimiter = limitSubmit.limit(); String redisKey = limitSubmit.key(); boolean needAllWait = limitSubmit.needAllWait(); String key = getRedisKey(sysUser,joinPoint, redisKey); Object result = redisUtil.get(key); if (result != null) { throw new JeecgBootException("請勿重復訪問!"); } redisUtil.set( key, sysUser.getId(),submitTimeLimiter); try { Object proceed = joinPoint.proceed(); return proceed; } catch (Throwable e) { log.error("Exception in {}.{}() with cause = \'{}\' and exception = \'{}\'", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName(), e.getCause() != null? e.getCause() : "NULL", e.getMessage(), e); throw e; }finally { if(!needAllWait) { redisUtil.del(redisKey); } } } /** * 支持多參數,從請求參數進行處理 */ private String getRedisKey(LoginUser sysUser,ProceedingJoinPoint joinPoint ,String key ){ if(key.contains("%s")) { key = String.format(key, sysUser.getId()); } Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer(); String[] parameterNames = discoverer.getParameterNames(method); if (parameterNames != null) { for (int i=0; i < parameterNames.length; i++ ) { String item = parameterNames[i]; if(key.contains("#"+item)){ key = key.replace("#"+item, joinPoint.getArgs()[i].toString()); } } } return key.toString(); } } ``` **使用效果:** ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20200702225400154.png) ```java 使用: @LimitSubmit(key = "testLimit:%s:#orderId",limit = 10,needAllWait = true) %S 代表當前登錄人 #參數 代表從參數中獲取,支持多個參數 生成的redis key: testLimit:e9ca23d68d884d4ebb19d07889727dae:order1123123 ``` 1.限制對某個接口的訪問,針對所有人 ,則去除%S 2.限制某個人對某個接口的訪問,則 %S 3.限制某個人對某個接口的業務參數的訪問,則 %S:#參數1:#參數2 ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20200702225331667.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzE5NTI4MjQ5,size_16,color_FFFFFF,t_70) ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20200702225345331.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzE5NTI4MjQ5,size_16,color_FFFFFF,t_70)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看