作者:CS打贏你 來(lái)源:https://blog.csdn.net/weixin_42533856/article/details/82593123
說(shuō)明:使用了注解的方式進(jìn)行對(duì)接口防刷的功能,非常高大上,本文章僅供參考 一,技術(shù)要點(diǎn):springboot的基本知識(shí),redis基本操作,
首先是寫(xiě)一個(gè)注解類:
/**
* @author yhq
* @date 2018/9/10 15:52
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface AccessLimit {
int seconds();
int maxCount();
boolean needLogin()default true;
}
攔截器中實(shí)現(xiàn):
注冊(cè)到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)
@RequestMApping("/fangshua")
@ResponseBody
public Result<String> fangshua(){
return Result.success("請(qǐng)求成功");
}






