作者:CS打赢你 来源:https://blog.csdn.net/weixin_42533856/article/details/82593123
说明:使用了注解的方式进行对接口防刷的功能,非常高大上,本文章仅供参考 一,技术要点:springboot的基本知识,redis基本操作,
/** * @author yhq * @date 2018/9/10 15:52 */ @Retention(RUNTIME) @Target(METHOD) public @interface AccessLimit { int seconds(); int maxCount(); boolean needLogin()default true; }
/** * @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); } }
/** * @author yhq * @date 2018/9/10 15:49 */ @Controller public class FangshuaController { @AccessLimit(seconds=5, maxCount=5, needLogin=true) @RequestMApping("/fangshua") @ResponseBody public Result<String> fangshua(){ return Result.success("请求成功"); }