| 12345678910111213141516171819202122232425262728293031323334 |
- package com.tzld.piaoquan.api.annotation;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- /**
- * 限流注解,支持按 IP 或按账号维度
- */
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- public @interface RateLimit {
- /**
- * 限流时间窗口,单位秒
- */
- long timeWindow() default 60;
- /**
- * 时间窗口内最大请求数
- */
- long maxRequests() default 10;
- /**
- * 限流提示信息
- */
- String message() default "请求过于频繁,请稍后再试";
- /**
- * 是否按账号限流(需要登录态),true 时以 accountId 为限流键,false 时以 IP 为限流键
- */
- boolean limitByAccount() default false;
- }
|