作者:CS打赢你 来源:https://blog.csdn.net/weixin_42533856/article/details/82593123
说明:使用了注解的方式进行对接口防刷的功能,非常高大上,本文章仅供参考 一,技术要点:springboot的基本知识,基本操作,
首先是写一个注解类:
/**
* @author yhq
* @date 2018/9/10 15:52
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface AccessLimit {
int seconds();
int maxCount();
boolean needLogin()default true;
}
拦截器中实现:
注册到springboot中
/**
* @author yhq
* @date 2018/9/10 15:58
*/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Autowired
private FangshuaInterceptor interceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor);
}
}
在Controller中加入注解
/**
* @author yhq
* @date 2018/9/10 15:49
*/
@Controller
public class FangshuaController {
@AccessLimit(seconds=5, maxCount=5, needLogin=true)
@RequestMing("/fangshua")
@ResponseBody
public Result<String> fangshua(){
return Result.success("请求成功");
}胜象大百科 








