# nrs-spring-boot-starter **Repository Path**: lxihaa/nrs-spring-boot-starter ## Basic Information - **Project Name**: nrs-spring-boot-starter - **Description**: 可以简单的完成防止重复的请求的功能实现的springboot的starter - **Primary Language**: Unknown - **License**: WTFPL - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2023-05-15 - **Last Updated**: 2023-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nrs-spring-boot-starter **简介:** 该组件防止接口在一定时间内频繁请求** ## 一、快速上手 1. 引入maven相关依赖 ```xml com.uhu nrs-spring-boot-starter 1.0-SNAPSHOT ``` 2. 在启动类添加注解启动 ```java @Slf4j @SpringBootApplication @EnableNRS public class GoodsApplication { public static void main(String[] args) { SpringApplication.run(GoodsApplication.class, args); } } ``` 3. 在对应的controller类上添加注解 ```java @RestController @RequestMapping("/p-goods-specification") @NoRepeatSubmit public class PGoodsSpecificationController { } ``` **注意:在类上添加NRS注解后,方法上的注解无效** 4. 在controller对应方法上添加注解 ```java @RestController @RequestMapping("/p-goods-specification") public class PGoodsSpecificationController { @NoRepeatSubmit @GetMapping("/test") public Result test(){ return Result.ok() } } ``` 5. 测试 ![1678951619076](README.assets/1678951619076.png) ## 二、参数设置 - 默认的全局请求次数限制未4次 - 默认的全局判断时间为20秒 ### 自定义全局时间 在yaml配置中添加对应属性即可 ```yaml nrs: globalIntervalTime: 20 globalRequestCount: 3 ``` 单位为:s(秒) ### 自定义时间 在注解中默认有两个属性 - requestCount:在合理时间范围内的允许请求次数 - intervalTime: 合理的时间范围(秒) **样例** ```java // 允许30s内请求5次 @NoRepeatSubmit(requestCount = 5, intervalTime = 30) ``` ### 自定义返回对象 默认的返回对象 ![1678951647356](README.assets/1678951619076.png) **修改为自定义的返回对象** 只需修改 ```java // CustomRes自定义返回对象 com.uhu.nrs.util.NrsUtil.setNrsRes(CustomRes); ```