springboot接口限制访问次数

对接口访问次数的限制 是从java版web项目公众号中看到 于是百度结合自己现有项目写了一下

首先需要定义一个注解

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @Auther: lirui
 * @Date: 2020/11/1 0:12
 * @Description: 接口防刷注解类
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AccessLimit {

    int seconds();
    int maxcount();
    boolean needLogin() default true;
}

接口防刷拦截器

import com.bigdata.bigdata.annotations.AccessLimit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.

你可能感兴趣的:(工作中遇到的问题,spring,redis)