防止重复提交的方式有很多
可以用数据库的唯一索引,保证数据完整性
在业务层用select....for update,依然是使用数据库的事务来做的
使用注解+拦截器 HandlerIntercetper+redis
我这里使用注解+aop+redis。
1、注解
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)public @interface Resubmit { int interval() default 5; // s 单位为秒,x秒内防止重复提交}2、切面实现,
String CACHE_KEY = "resubmit:"= "@annotation(resubmit)" Object around(ProceedingJoinPoint point, Resubmit resubmit) ==== === CACHE_KEY + username + request.getMethod() +=== BizException("请勿重复提交"3、使用
@PutMapping
@Resubmit public JsonResult<Boolean> save(@Validated @RequestBody EnterpriseRecheckEditRequest request){ return JsonResult.success(enterpriseRecheckService.add(request));
}对比是否是同一数据重复提交,判断方式还可以加入请求参数

评论留言
暂时没有留言!