当前位置:   article > 正文

springboot表单重复提交校验(基于注解和AOP)_springboot重复提交校验

springboot重复提交校验

自我记录,有用得到的拿去用,有问题私信我

  • 定义注解

  1. @Target({ElementType.METHOD})
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. public @interface NoRepeatSubmit {
  5. /**
  6. * 默认1s钟以内算重复提交
  7. * @return
  8. */
  9. long timeout() default 1;
  10. }
  • 定义切面

  1. @Aspect
  2. @Component
  3. public class NoRepeatSubmitAop {
  4. @Resource
  5. private RedisUtils redisUtils;
  6. /**
  7. * 定义切入点
  8. */
  9. @Pointcut("@annotation(app.annotation.NoRepeatSubmit)")
  10. public void noRepeat() {}
  11. /**
  12. * 前置通知:在连接点之前执行的通知
  13. * @param point
  14. * @throws Throwable
  15. */
  16. @Before("noRepeat()")
  17. public void before(JoinPoint point) throws Exception{
  18. ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  19. HttpServ
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/234351
推荐阅读
相关标签
  

闽ICP备14008679号