JAVA防重注解,用于接口防重提交 JAVA anti duplication annotation, used for interface anti duplication submission
- 支持本地和redis多种缓存策略(Supports multiple local and Redis caching strategies)
- 支持全局配置和注解配置(global and annotation configurations)
- 支持自定义响应文案(custom response copy)
- 支持自动释放和定时释放(automatic and scheduled releases)
项目已经上传中央仓库,您可以通过pom引入如下代码
The project has been uploaded to the central warehouse. You can import the following code through POM
<dependency>
<groupId>com.aeert</groupId>
<artifactId>mlock</artifactId>
<version>2.8.1.RELEASE</version>
</dependency>
启动类加上组件的路径(com.aeert)扫描即可,路径(com.aeert)需要放在最后面
The path of the startup class plus the component( com.aeert )Scan, path( com.aeert )It needs to be at the back
@SpringBootApplication(scanBasePackages = {"com.example.vfilterdemo", "com.aeert"})
public class VfilterDemoApplication {
public static void main(String[] args) {
SpringApplication.run(VfilterDemoApplication.class, args);
}
}
通过一行注解即可使用,支持spel表达式
It can be used with a single line of annotation and supports Spel expressions
@MLock
@PostMapping("/areaList")
public R areaList() {
……
}
或者
@PostMapping("/myAssets/update")
@MLock(key = {"#p0.userId", "#p1.id"})
public R update(@ApiIgnore @LoginUser UserEntity user, @RequestBody UserTunnelEntity userTunnelEntity) {
……
}
或者
@PostMapping("/myAssets/update")
@MLock(key = {"#user.userId", "#p1.id"})
public R update(@ApiIgnore @LoginUser UserEntity user, @RequestBody UserTunnelEntity userTunnelEntity) {
……
}
你也可以自定义自定义默认参数,但这不是必须的,可配置的参数定义如下
You can also customize default parameters, but this is not necessary. The configurable parameters are defined as follows
/**
* MLock锁文案,(可自定义适合场景的文案)
*/
String message() default "操作正在进行中!";
/**
* MLock锁的有效期(单位:秒)
**/
long expires() default 60L;
/**
* 是否使用本地缓存(默认使用redis,开启的话使用caffeine,仅建议单机场景开启)
**/
boolean localCache() default false;
/**
* 请求结束是否自动释放(自动释放适合业务方法,不自动释放适合场景如表单10s内防重复提交)
**/
boolean automatic() default true;
application.yml
mlock:
automatic: true
message: 操作频繁,请稍后~
expires: 30
local-cache: true
application.properties
mlock.automatic=true
mlock.message=操作频繁,请稍后~
mlock.expires=30
mlock.local-cache=true